Skip to content

Commit 9b237f4

Browse files
committed
Print to first null when outputting payload to string
1 parent b20421b commit 9b237f4

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

discon-client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func DISCON(avrSwap *C.float, aviFail *C.int, accInFile, avcOutName, avcMsg *C.c
118118
ws.WriteMessage(websocket.BinaryMessage, b)
119119

120120
if debug {
121-
log.Println("discon-client: sent payload:", payload)
121+
log.Println("discon-client: sent payload:\n", payload)
122122
}
123123

124124
// Read response from server
@@ -134,7 +134,7 @@ func DISCON(avrSwap *C.float, aviFail *C.int, accInFile, avcOutName, avcMsg *C.c
134134
}
135135

136136
if debug {
137-
log.Println("discon-client: received payload:", payload)
137+
log.Println("discon-client: received payload:\n", payload)
138138
}
139139

140140
// Set fail flag

payload.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,26 @@ func (p *Payload) UnmarshalBinary(data []byte) error {
120120
}
121121

122122
func (p Payload) String() string {
123+
i0InFile := bytes.IndexByte(p.InFile, 0)
124+
if i0InFile < 0 {
125+
i0InFile = len(p.InFile)
126+
}
127+
i0OutName := bytes.IndexByte(p.OutName, 0)
128+
if i0OutName < 0 {
129+
i0OutName = len(p.OutName)
130+
}
131+
i0Msg := bytes.IndexByte(p.Msg, 0)
132+
if i0Msg < 0 {
133+
i0Msg = len(p.Msg)
134+
}
123135
return fmt.Sprintf("avrSWAP: %v\n"+
124136
"aviFAIL: %v\n"+
125137
"accINFILE: '%s'\n"+
126138
"avcOUTNAME: '%s'\n"+
127139
"avcMSG: '%s'\n",
128-
p.Swap[:129], p.Fail, p.InFile, p.OutName, p.Msg)
140+
p.Swap[:129],
141+
p.Fail,
142+
p.InFile[:i0InFile],
143+
p.OutName[:i0OutName],
144+
p.Msg[:i0Msg])
129145
}

0 commit comments

Comments
 (0)