package pgproto3
import (
"bytes"
"encoding/json"
"errors"
"github.com/jackc/pgx/v5/internal/pgio"
)
type Close struct {
ObjectType byte
Name string
}
func (*Close ) Frontend () {}
func (dst *Close ) Decode (src []byte ) error {
if len (src ) < 2 {
return &invalidMessageFormatErr {messageType : "Close" }
}
dst .ObjectType = src [0 ]
rp := 1
idx := bytes .IndexByte (src [rp :], 0 )
if idx != len (src [rp :])-1 {
return &invalidMessageFormatErr {messageType : "Close" }
}
dst .Name = string (src [rp : len (src )-1 ])
return nil
}
func (src *Close ) Encode (dst []byte ) []byte {
dst = append (dst , 'C' )
sp := len (dst )
dst = pgio .AppendInt32 (dst , -1 )
dst = append (dst , src .ObjectType )
dst = append (dst , src .Name ...)
dst = append (dst , 0 )
pgio .SetInt32 (dst [sp :], int32 (len (dst [sp :])))
return dst
}
func (src Close ) MarshalJSON () ([]byte , error ) {
return json .Marshal (struct {
Type string
ObjectType string
Name string
}{
Type : "Close" ,
ObjectType : string (src .ObjectType ),
Name : src .Name ,
})
}
func (dst *Close ) UnmarshalJSON (data []byte ) error {
if string (data ) == "null" {
return nil
}
var msg struct {
ObjectType string
Name string
}
if err := json .Unmarshal (data , &msg ); err != nil {
return err
}
if len (msg .ObjectType ) != 1 {
return errors .New ("invalid length for Close.ObjectType" )
}
dst .ObjectType = byte (msg .ObjectType [0 ])
dst .Name = msg .Name
return nil
}
The pages are generated with Golds v0.6.7 . (GOOS=linux 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 .