package pgproto3
import (
"bytes"
"encoding/json"
"github.com/jackc/pgx/v5/internal/pgio"
)
type CommandComplete struct {
CommandTag []byte
}
func (*CommandComplete ) Backend () {}
func (dst *CommandComplete ) Decode (src []byte ) error {
idx := bytes .IndexByte (src , 0 )
if idx == -1 {
return &invalidMessageFormatErr {messageType : "CommandComplete" , details : "unterminated string" }
}
if idx != len (src )-1 {
return &invalidMessageFormatErr {messageType : "CommandComplete" , details : "string terminated too early" }
}
dst .CommandTag = src [:idx ]
return nil
}
func (src *CommandComplete ) Encode (dst []byte ) []byte {
dst = append (dst , 'C' )
sp := len (dst )
dst = pgio .AppendInt32 (dst , -1 )
dst = append (dst , src .CommandTag ...)
dst = append (dst , 0 )
pgio .SetInt32 (dst [sp :], int32 (len (dst [sp :])))
return dst
}
func (src CommandComplete ) MarshalJSON () ([]byte , error ) {
return json .Marshal (struct {
Type string
CommandTag string
}{
Type : "CommandComplete" ,
CommandTag : string (src .CommandTag ),
})
}
func (dst *CommandComplete ) UnmarshalJSON (data []byte ) error {
if string (data ) == "null" {
return nil
}
var msg struct {
CommandTag string
}
if err := json .Unmarshal (data , &msg ); err != nil {
return err
}
dst .CommandTag = []byte (msg .CommandTag )
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 .