MCPcopy Create free account
hub / github.com/PostHog/duckgres / WriteMessage

Function WriteMessage

server/wire/protocol.go:187–207  ·  view source on GitHub ↗

writeMessage writes a message to the client

(w io.Writer, msgType byte, data []byte)

Source from the content-addressed store, hash-verified

185 if length < 4 || length > maxMessageLength {
186 return 0, nil, fmt.Errorf("invalid message length: %d", length)
187 }
188
189 // Read message body
190 body := make([]byte, length-4)
191 if length > 4 {
192 if _, err := io.ReadFull(r, body); err != nil {
193 return 0, nil, fmt.Errorf("failed to read message body: %w", err)
194 }
195 }
196
197 return msgType, body, nil
198}
199
200// writeMessage writes a message to the client
201func WriteMessage(w io.Writer, msgType byte, data []byte) error {
202 // Write message type
203 if _, err := w.Write([]byte{msgType}); err != nil {
204 return err
205 }
206
207 // Write length (includes itself, 4 bytes)
208 length := int32(len(data) + 4)
209 if err := binary.Write(w, binary.BigEndian, length); err != nil {
210 return err

Callers 15

TestWriteMessageFunction · 0.92
TestMessageRoundTripFunction · 0.92
passwordMessageFunction · 0.92
TestReadMessageValidFunction · 0.85
TestReadMessageEmptyBodyFunction · 0.85
WriteAuthOKFunction · 0.85

Calls 1

WriteMethod · 0.45

Tested by 5

TestWriteMessageFunction · 0.74
TestMessageRoundTripFunction · 0.74
passwordMessageFunction · 0.74
TestReadMessageValidFunction · 0.68
TestReadMessageEmptyBodyFunction · 0.68