package pgproto3
import (
)
type CopyBothResponse struct {
OverallFormat byte
ColumnFormatCodes []uint16
}
func (*CopyBothResponse) () {}
func ( *CopyBothResponse) ( []byte) error {
:= bytes.NewBuffer()
if .Len() < 3 {
return &invalidMessageFormatErr{messageType: "CopyBothResponse"}
}
:= .Next(1)[0]
:= int(binary.BigEndian.Uint16(.Next(2)))
if .Len() != *2 {
return &invalidMessageFormatErr{messageType: "CopyBothResponse"}
}
:= make([]uint16, )
for := range {
[] = binary.BigEndian.Uint16(.Next(2))
}
* = CopyBothResponse{OverallFormat: , ColumnFormatCodes: }
return nil
}
func ( *CopyBothResponse) ( []byte) ([]byte, error) {
, := beginMessage(, 'W')
= append(, .OverallFormat)
if len(.ColumnFormatCodes) > math.MaxUint16 {
return nil, errors.New("too many column format codes")
}
= pgio.AppendUint16(, uint16(len(.ColumnFormatCodes)))
for , := range .ColumnFormatCodes {
= pgio.AppendUint16(, )
}
return finishMessage(, )
}
func ( CopyBothResponse) () ([]byte, error) {
return json.Marshal(struct {
string
[]uint16
}{
: "CopyBothResponse",
: .ColumnFormatCodes,
})
}
func ( *CopyBothResponse) ( []byte) error {
if string() == "null" {
return nil
}
var struct {
string
[]uint16
}
if := json.Unmarshal(, &); != nil {
return
}
if len(.) != 1 {
return errors.New("invalid length for CopyBothResponse.OverallFormat")
}
.OverallFormat = .[0]
.ColumnFormatCodes = .
return nil
}