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

Method Decode

pgproto3/row_description.go:58–100  ·  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

56// Decode decodes src into dst. src must contain the complete message with the exception of the initial 1 byte message
57// type identifier and 4 byte message length.
58func (dst *RowDescription) Decode(src []byte) error {
59 if len(src) < 2 {
60 return &invalidMessageFormatErr{messageType: "RowDescription"}
61 }
62 fieldCount := int(binary.BigEndian.Uint16(src))
63 rp := 2
64
65 dst.Fields = dst.Fields[0:0]
66
67 for range fieldCount {
68 var fd FieldDescription
69
70 idx := bytes.IndexByte(src[rp:], 0)
71 if idx < 0 {
72 return &invalidMessageFormatErr{messageType: "RowDescription"}
73 }
74 fd.Name = src[rp : rp+idx]
75 rp += idx + 1
76
77 // Since buf.Next() doesn't return an error if we hit the end of the buffer
78 // check Len ahead of time
79 if len(src[rp:]) < 18 {
80 return &invalidMessageFormatErr{messageType: "RowDescription"}
81 }
82
83 fd.TableOID = binary.BigEndian.Uint32(src[rp:])
84 rp += 4
85 fd.TableAttributeNumber = binary.BigEndian.Uint16(src[rp:])
86 rp += 2
87 fd.DataTypeOID = binary.BigEndian.Uint32(src[rp:])
88 rp += 4
89 fd.DataTypeSize = int16(binary.BigEndian.Uint16(src[rp:]))
90 rp += 2
91 fd.TypeModifier = int32(binary.BigEndian.Uint32(src[rp:]))
92 rp += 4
93 fd.Format = int16(binary.BigEndian.Uint16(src[rp:]))
94 rp += 2
95
96 dst.Fields = append(dst.Fields, fd)
97 }
98
99 return nil
100}
101
102// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
103func (src *RowDescription) Encode(dst []byte) ([]byte, error) {

Callers 1

FuzzRowDescriptionFunction · 0.95

Calls 2

Uint16Method · 0.80
Uint32Method · 0.80

Tested by 1

FuzzRowDescriptionFunction · 0.76