package pgproto3
import (
)
type BackendKeyData struct {
ProcessID uint32
SecretKey []byte
}
func (*BackendKeyData) () {}
func ( *BackendKeyData) ( []byte) error {
if len() < 8 {
return &invalidMessageLenErr{messageType: "BackendKeyData", expectedLen: 8, actualLen: len()}
}
.ProcessID = binary.BigEndian.Uint32([:4])
.SecretKey = make([]byte, len()-4)
copy(.SecretKey, [4:])
return nil
}
func ( *BackendKeyData) ( []byte) ([]byte, error) {
, := beginMessage(, 'K')
= pgio.AppendUint32(, .ProcessID)
= append(, .SecretKey...)
return finishMessage(, )
}
func ( BackendKeyData) () ([]byte, error) {
return json.Marshal(struct {
string
uint32
string
}{
: "BackendKeyData",
: .ProcessID,
: hex.EncodeToString(.SecretKey),
})
}
func ( *BackendKeyData) ( []byte) error {
var struct {
uint32
string
}
if := json.Unmarshal(, &); != nil {
return
}
.ProcessID = .
, := hex.DecodeString(.)
if != nil {
return
}
.SecretKey =
return nil
}