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)
| 10 | |
| 11 | // buildStartupMessage encodes a v3 startup packet: int32 length (includes |
| 12 | // itself), int32 protocol version, then null-terminated key/value pairs. |
| 13 | func 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 |
no test coverage detected