File tree 1 file changed +7
-8
lines changed
1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -125,15 +125,14 @@ func sendPacket(w io.Writer, m encoding.BinaryMarshaler) error {
125
125
} else if debugDumpTxPacket {
126
126
debug ("send packet: %s %d bytes" , fxp (bb [0 ]), len (bb ))
127
127
}
128
- l := uint32 (len (bb ))
129
- hdr := []byte {byte (l >> 24 ), byte (l >> 16 ), byte (l >> 8 ), byte (l )}
130
- _ , err = w .Write (hdr )
131
- if err != nil {
132
- return errors .Errorf ("failed to send packet header: %v" , err )
133
- }
134
- _ , err = w .Write (bb )
128
+ // Slide packet down 4 bytes to make room for length header.
129
+ packet := append (bb , make ([]byte , 4 )... ) // optimistically assume bb has capacity
130
+ copy (packet [4 :], bb )
131
+ binary .BigEndian .PutUint32 (packet [:4 ], uint32 (len (bb )))
132
+
133
+ _ , err = w .Write (packet )
135
134
if err != nil {
136
- return errors .Errorf ("failed to send packet body : %v" , err )
135
+ return errors .Errorf ("failed to send packet: %v" , err )
137
136
}
138
137
return nil
139
138
}
You can’t perform that action at this time.
0 commit comments