package pgproto3
import (
)
type Parse struct {
Name string
Query string
ParameterOIDs []uint32
}
func (*Parse) () {}
func ( *Parse) ( []byte) error {
* = Parse{}
:= bytes.NewBuffer()
, := .ReadBytes(0)
if != nil {
return
}
.Name = string([:len()-1])
, = .ReadBytes(0)
if != nil {
return
}
.Query = string([:len()-1])
if .Len() < 2 {
return &invalidMessageFormatErr{messageType: "Parse"}
}
:= int(binary.BigEndian.Uint16(.Next(2)))
for range {
if .Len() < 4 {
return &invalidMessageFormatErr{messageType: "Parse"}
}
.ParameterOIDs = append(.ParameterOIDs, binary.BigEndian.Uint32(.Next(4)))
}
return nil
}
func ( *Parse) ( []byte) ([]byte, error) {
, := beginMessage(, 'P')
= append(, .Name...)
= append(, 0)
= append(, .Query...)
= append(, 0)
if len(.ParameterOIDs) > math.MaxUint16 {
return nil, errors.New("too many parameter oids")
}
= pgio.AppendUint16(, uint16(len(.ParameterOIDs)))
for , := range .ParameterOIDs {
= pgio.AppendUint32(, )
}
return finishMessage(, )
}
func ( Parse) () ([]byte, error) {
return json.Marshal(struct {
string
string
string
[]uint32
}{
: "Parse",
: .Name,
: .Query,
: .ParameterOIDs,
})
}