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

Method Encode

pgproto3/bind.go:113–152  ·  view source on GitHub ↗

Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.

(dst []byte)

Source from the content-addressed store, hash-verified

111
112// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
113func (src *Bind) Encode(dst []byte) ([]byte, error) {
114 dst, sp := beginMessage(dst, 'B')
115
116 dst = append(dst, src.DestinationPortal...)
117 dst = append(dst, 0)
118 dst = append(dst, src.PreparedStatement...)
119 dst = append(dst, 0)
120
121 if len(src.ParameterFormatCodes) > math.MaxUint16 {
122 return nil, errors.New("too many parameter format codes")
123 }
124 dst = pgio.AppendUint16(dst, uint16(len(src.ParameterFormatCodes)))
125 for _, fc := range src.ParameterFormatCodes {
126 dst = pgio.AppendInt16(dst, fc)
127 }
128
129 if len(src.Parameters) > math.MaxUint16 {
130 return nil, errors.New("too many parameters")
131 }
132 dst = pgio.AppendUint16(dst, uint16(len(src.Parameters)))
133 for _, p := range src.Parameters {
134 if p == nil {
135 dst = pgio.AppendInt32(dst, -1)
136 continue
137 }
138
139 dst = pgio.AppendInt32(dst, int32(len(p)))
140 dst = append(dst, p...)
141 }
142
143 if len(src.ResultFormatCodes) > math.MaxUint16 {
144 return nil, errors.New("too many result format codes")
145 }
146 dst = pgio.AppendUint16(dst, uint16(len(src.ResultFormatCodes)))
147 for _, fc := range src.ResultFormatCodes {
148 dst = pgio.AppendInt16(dst, fc)
149 }
150
151 return finishMessage(dst, sp)
152}
153
154// MarshalJSON implements encoding/json.Marshaler.
155func (src Bind) MarshalJSON() ([]byte, error) {

Callers

nothing calls this directly

Calls 5

AppendUint16Function · 0.92
AppendInt16Function · 0.92
AppendInt32Function · 0.92
beginMessageFunction · 0.85
finishMessageFunction · 0.85

Tested by

no test coverage detected