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

Function ReadMessage

server/wire/protocol.go:156–184  ·  view source on GitHub ↗

readMessage reads a single message from the client

(r io.Reader)

Source from the content-addressed store, hash-verified

154 // with "slice bounds out of range". Mirrors the key-scan guard above.
155 if valEnd >= len(data) {
156 break
157 }
158 value := string(data[:valEnd])
159 data = data[valEnd+1:]
160
161 if key != "" {
162 params[key] = value
163 }
164 }
165
166 return StartupMessage{Params: params}, nil
167}
168
169// readMessage reads a single message from the client
170func ReadMessage(r io.Reader) (byte, []byte, error) {
171 // Read message type (1 byte)
172 typeBuf := make([]byte, 1)
173 if _, err := io.ReadFull(r, typeBuf); err != nil {
174 return 0, nil, err
175 }
176 msgType := typeBuf[0]
177
178 // Read message length (4 bytes, includes itself)
179 var length int32
180 if err := binary.Read(r, binary.BigEndian, &length); err != nil {
181 return 0, nil, fmt.Errorf("failed to read message length: %w", err)
182 }
183
184 // Validate before allocating: minimum 4 = the length field itself.
185 if length < 4 || length > maxMessageLength {
186 return 0, nil, fmt.Errorf("invalid message length: %d", length)
187 }

Callers 15

TestReadMessageFunction · 0.92
TestMessageRoundTripFunction · 0.92
handleCopyInMethod · 0.92
ReadMethod · 0.92
handleCopyInBinaryMethod · 0.92
handleStartupMethod · 0.92
messageLoopMethod · 0.92
authenticateChildClientFunction · 0.92

Calls 1

ReadMethod · 0.45