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

Method Decode

pgproto3/bind.go:28–110  ·  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

26// Decode decodes src into dst. src must contain the complete message with the exception of the initial 1 byte message
27// type identifier and 4 byte message length.
28func (dst *Bind) Decode(src []byte) error {
29 *dst = Bind{}
30
31 idx := bytes.IndexByte(src, 0)
32 if idx < 0 {
33 return &invalidMessageFormatErr{messageType: "Bind"}
34 }
35 dst.DestinationPortal = string(src[:idx])
36 rp := idx + 1
37
38 idx = bytes.IndexByte(src[rp:], 0)
39 if idx < 0 {
40 return &invalidMessageFormatErr{messageType: "Bind"}
41 }
42 dst.PreparedStatement = string(src[rp : rp+idx])
43 rp += idx + 1
44
45 if len(src[rp:]) < 2 {
46 return &invalidMessageFormatErr{messageType: "Bind"}
47 }
48 parameterFormatCodeCount := int(binary.BigEndian.Uint16(src[rp:]))
49 rp += 2
50
51 if parameterFormatCodeCount > 0 {
52 dst.ParameterFormatCodes = make([]int16, parameterFormatCodeCount)
53
54 if len(src[rp:]) < len(dst.ParameterFormatCodes)*2 {
55 return &invalidMessageFormatErr{messageType: "Bind"}
56 }
57 for i := range parameterFormatCodeCount {
58 dst.ParameterFormatCodes[i] = int16(binary.BigEndian.Uint16(src[rp:]))
59 rp += 2
60 }
61 }
62
63 if len(src[rp:]) < 2 {
64 return &invalidMessageFormatErr{messageType: "Bind"}
65 }
66 parameterCount := int(binary.BigEndian.Uint16(src[rp:]))
67 rp += 2
68
69 if parameterCount > 0 {
70 dst.Parameters = make([][]byte, parameterCount)
71
72 for i := range parameterCount {
73 if len(src[rp:]) < 4 {
74 return &invalidMessageFormatErr{messageType: "Bind"}
75 }
76
77 msgSize := int(int32(binary.BigEndian.Uint32(src[rp:])))
78 rp += 4
79
80 // null
81 if msgSize == -1 {
82 continue
83 }
84
85 if msgSize < 0 || len(src[rp:]) < msgSize {

Callers 2

FuzzBindFunction · 0.95

Calls 2

Uint16Method · 0.80
Uint32Method · 0.80

Tested by 2

FuzzBindFunction · 0.76