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

Function buildStartupMessage

server/wire/protocol_test.go:12–27  ·  view source on GitHub ↗

buildStartupMessage encodes a v3 startup packet: int32 length (includes itself), int32 protocol version, then null-terminated key/value pairs.

(protocolVersion uint32, params map[string]string)

Source from the content-addressed store, hash-verified

10
11// buildStartupMessage encodes a v3 startup packet: int32 length (includes
12// itself), int32 protocol version, then null-terminated key/value pairs.
13func buildStartupMessage(protocolVersion uint32, params map[string]string) []byte {
14 var body bytes.Buffer
15 _ = binary.Write(&body, binary.BigEndian, protocolVersion)
16 for k, v := range params {
17 body.WriteString(k)
18 body.WriteByte(0)
19 body.WriteString(v)
20 body.WriteByte(0)
21 }
22 body.WriteByte(0) // terminator
23
24 var msg bytes.Buffer
25 _ = binary.Write(&msg, binary.BigEndian, int32(body.Len()+4))
26 msg.Write(body.Bytes())
27 return msg.Bytes()
28}
29
30// buildRawStartup writes an arbitrary (possibly invalid) length header

Callers 2

Calls 1

WriteMethod · 0.45

Tested by

no test coverage detected