MCPcopy
hub / github.com/jackc/pgx / Decode

Method Decode

pgproto3/cancel_request.go:22–40  ·  view source on GitHub ↗
(src []byte)

Source from the content-addressed store, hash-verified

20func (*CancelRequest) Frontend() {}
21
22func (dst *CancelRequest) Decode(src []byte) error {
23 if len(src) < 12 {
24 return errors.New("cancel request too short")
25 }
26 if len(src) > 264 {
27 return errors.New("cancel request too long")
28 }
29
30 requestCode := binary.BigEndian.Uint32(src)
31 if requestCode != cancelRequestCode {
32 return errors.New("bad cancel request code")
33 }
34
35 dst.ProcessID = binary.BigEndian.Uint32(src[4:])
36 dst.SecretKey = make([]byte, len(src)-8)
37 copy(dst.SecretKey, src[8:])
38
39 return nil
40}
41
42// Encode encodes src into dst. dst will include the 4 byte message length.
43func (src *CancelRequest) Encode(dst []byte) ([]byte, error) {

Callers 1

TestCancelRequestDecodeFunction · 0.95

Calls 1

Uint32Method · 0.80

Tested by 1

TestCancelRequestDecodeFunction · 0.76