package pgproto3
import (
)
type NegotiateProtocolVersion struct {
NewestMinorProtocol uint32
UnrecognizedOptions []string
}
func (*NegotiateProtocolVersion) () {}
func ( *NegotiateProtocolVersion) ( []byte) error {
if len() < 8 {
return &invalidMessageLenErr{messageType: "NegotiateProtocolVersion", expectedLen: 8, actualLen: len()}
}
.NewestMinorProtocol = binary.BigEndian.Uint32([:4])
:= int(binary.BigEndian.Uint32([4:8]))
:= 8
:=
if := len() - ; > {
=
}
.UnrecognizedOptions = make([]string, 0, )
for := 0; < ; ++ {
if >= len() {
return &invalidMessageFormatErr{messageType: "NegotiateProtocolVersion"}
}
:=
for < len() && [] != 0 {
++
}
if >= len() {
return &invalidMessageFormatErr{messageType: "NegotiateProtocolVersion"}
}
.UnrecognizedOptions = append(.UnrecognizedOptions, string([:]))
= + 1
}
return nil
}
func ( *NegotiateProtocolVersion) ( []byte) ([]byte, error) {
, := beginMessage(, 'v')
= pgio.AppendUint32(, .NewestMinorProtocol)
= pgio.AppendUint32(, uint32(len(.UnrecognizedOptions)))
for , := range .UnrecognizedOptions {
= append(, ...)
= append(, 0)
}
return finishMessage(, )
}
func ( NegotiateProtocolVersion) () ([]byte, error) {
return json.Marshal(struct {
string
uint32
[]string
}{
: "NegotiateProtocolVersion",
: .NewestMinorProtocol,
: .UnrecognizedOptions,
})
}
func ( *NegotiateProtocolVersion) ( []byte) error {
var struct {
uint32
[]string
}
if := json.Unmarshal(, &); != nil {
return
}
.NewestMinorProtocol = .
.UnrecognizedOptions = .
return nil
}