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

Method Decode

pgproto3/data_row.go:22–62  ·  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

20// Decode decodes src into dst. src must contain the complete message with the exception of the initial 1 byte message
21// type identifier and 4 byte message length.
22func (dst *DataRow) Decode(src []byte) error {
23 if len(src) < 2 {
24 return &invalidMessageFormatErr{messageType: "DataRow"}
25 }
26 rp := 0
27 fieldCount := int(binary.BigEndian.Uint16(src[rp:]))
28 rp += 2
29
30 // If the capacity of the values slice is too small OR substantially too
31 // large reallocate. This is too avoid one row with many columns from
32 // permanently allocating memory.
33 if cap(dst.Values) < fieldCount || cap(dst.Values)-fieldCount > 32 {
34 newCap := max(32, fieldCount)
35 dst.Values = make([][]byte, fieldCount, newCap)
36 } else {
37 dst.Values = dst.Values[:fieldCount]
38 }
39
40 for i := range fieldCount {
41 if len(src[rp:]) < 4 {
42 return &invalidMessageFormatErr{messageType: "DataRow"}
43 }
44
45 valueLen := int(int32(binary.BigEndian.Uint32(src[rp:])))
46 rp += 4
47
48 // null
49 if valueLen == -1 {
50 dst.Values[i] = nil
51 } else {
52 if len(src[rp:]) < valueLen || valueLen < 0 {
53 return &invalidMessageFormatErr{messageType: "DataRow"}
54 }
55
56 dst.Values[i] = src[rp : rp+valueLen : rp+valueLen]
57 rp += valueLen
58 }
59 }
60
61 return nil
62}
63
64// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
65func (src *DataRow) Encode(dst []byte) ([]byte, error) {

Callers 1

FuzzDataRowFunction · 0.95

Calls 2

Uint16Method · 0.80
Uint32Method · 0.80

Tested by 1

FuzzDataRowFunction · 0.76