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

Function encodeCopyValue

values.go:27–44  ·  view source on GitHub ↗
(m *pgtype.Map, buf []byte, oid uint32, arg any)

Source from the content-addressed store, hash-verified

25}
26
27func encodeCopyValue(m *pgtype.Map, buf []byte, oid uint32, arg any) ([]byte, error) {
28 sp := len(buf)
29 buf = pgio.AppendInt32(buf, -1)
30 argBuf, err := m.Encode(oid, BinaryFormatCode, arg, buf)
31 if err != nil {
32 if argBuf2, err2 := tryScanStringCopyValueThenEncode(m, buf, oid, arg); err2 == nil {
33 argBuf = argBuf2
34 } else {
35 return nil, err
36 }
37 }
38
39 if argBuf != nil {
40 buf = argBuf
41 pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4))
42 }
43 return buf, nil
44}
45
46func tryScanStringCopyValueThenEncode(m *pgtype.Map, buf []byte, oid uint32, arg any) ([]byte, error) {
47 s, ok := arg.(string)

Callers 1

buildCopyBufMethod · 0.85

Calls 4

AppendInt32Function · 0.92
SetInt32Function · 0.92
EncodeMethod · 0.65

Tested by

no test coverage detected