Source File
startup_message.go
Belonging Package
github.com/jackc/pgproto3/v2
package pgproto3
import (
)
const ProtocolVersionNumber = 196608 // 3.0
type StartupMessage struct {
ProtocolVersion uint32
Parameters map[string]string
}
func (*StartupMessage) () {}
func ( *StartupMessage) ( []byte) error {
if len() < 4 {
return errors.New("startup message too short")
}
.ProtocolVersion = binary.BigEndian.Uint32()
:= 4
if .ProtocolVersion != ProtocolVersionNumber {
return fmt.Errorf("Bad startup message version number. Expected %d, got %d", ProtocolVersionNumber, .ProtocolVersion)
}
.Parameters = make(map[string]string)
for {
:= bytes.IndexByte([:], 0)
if < 0 {
return &invalidMessageFormatErr{messageType: "StartupMesage"}
}
:= string([ : +])
+= + 1
= bytes.IndexByte([:], 0)
if < 0 {
return &invalidMessageFormatErr{messageType: "StartupMesage"}
}
:= string([ : +])
+= + 1
.Parameters[] =
if len([:]) == 1 {
if [] != 0 {
return fmt.Errorf("Bad startup message last byte. Expected 0, got %d", [])
}
break
}
}
return nil
}
func ( *StartupMessage) ( []byte) []byte {
:= len()
= pgio.AppendInt32(, -1)
= pgio.AppendUint32(, .ProtocolVersion)
for , := range .Parameters {
= append(, ...)
= append(, 0)
= append(, ...)
= append(, 0)
}
= append(, 0)
pgio.SetInt32([:], int32(len([:])))
return
}
func ( StartupMessage) () ([]byte, error) {
return json.Marshal(struct {
string
uint32
map[string]string
}{
: "StartupMessage",
: .ProtocolVersion,
: .Parameters,
})
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |