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

Method Encode

pgproto3/function_call.go:98–124  ·  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

96
97// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
98func (src *FunctionCall) Encode(dst []byte) ([]byte, error) {
99 dst, sp := beginMessage(dst, 'F')
100 dst = pgio.AppendUint32(dst, src.Function)
101
102 if len(src.ArgFormatCodes) > math.MaxUint16 {
103 return nil, errors.New("too many arg format codes")
104 }
105 dst = pgio.AppendUint16(dst, uint16(len(src.ArgFormatCodes)))
106 for _, argFormatCode := range src.ArgFormatCodes {
107 dst = pgio.AppendUint16(dst, argFormatCode)
108 }
109
110 if len(src.Arguments) > math.MaxUint16 {
111 return nil, errors.New("too many arguments")
112 }
113 dst = pgio.AppendUint16(dst, uint16(len(src.Arguments)))
114 for _, argument := range src.Arguments {
115 if argument == nil {
116 dst = pgio.AppendInt32(dst, -1)
117 } else {
118 dst = pgio.AppendInt32(dst, int32(len(argument)))
119 dst = append(dst, argument...)
120 }
121 }
122 dst = pgio.AppendUint16(dst, src.ResultFormatCode)
123 return finishMessage(dst, sp)
124}

Callers 1

Calls 5

AppendUint32Function · 0.92
AppendUint16Function · 0.92
AppendInt32Function · 0.92
beginMessageFunction · 0.85
finishMessageFunction · 0.85

Tested by 1