Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
(dst []byte)
| 96 | |
| 97 | // Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length. |
| 98 | func (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 | } |