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

Method Decode

pgproto3/parse.go:24–54  ·  view source on GitHub ↗

Decode decodes src into dst. src must contain the complete message with the exception of the initial 1 byte message type identifier and 4 byte message length.

(src []byte)

Source from the content-addressed store, hash-verified

22// Decode decodes src into dst. src must contain the complete message with the exception of the initial 1 byte message
23// type identifier and 4 byte message length.
24func (dst *Parse) Decode(src []byte) error {
25 *dst = Parse{}
26
27 buf := bytes.NewBuffer(src)
28
29 b, err := buf.ReadBytes(0)
30 if err != nil {
31 return err
32 }
33 dst.Name = string(b[:len(b)-1])
34
35 b, err = buf.ReadBytes(0)
36 if err != nil {
37 return err
38 }
39 dst.Query = string(b[:len(b)-1])
40
41 if buf.Len() < 2 {
42 return &invalidMessageFormatErr{messageType: "Parse"}
43 }
44 parameterOIDCount := int(binary.BigEndian.Uint16(buf.Next(2)))
45
46 for range parameterOIDCount {
47 if buf.Len() < 4 {
48 return &invalidMessageFormatErr{messageType: "Parse"}
49 }
50 dst.ParameterOIDs = append(dst.ParameterOIDs, binary.BigEndian.Uint32(buf.Next(4)))
51 }
52
53 return nil
54}
55
56// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
57func (src *Parse) Encode(dst []byte) ([]byte, error) {

Callers 1

FuzzParseFunction · 0.95

Calls 4

Uint16Method · 0.80
Uint32Method · 0.80
LenMethod · 0.65
NextMethod · 0.65

Tested by 1

FuzzParseFunction · 0.76