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

Method Encode

pgtype/pgtype.go:1969–1994  ·  view source on GitHub ↗

Encode appends the encoded bytes of value to buf. If value is the SQL value NULL then append nothing and return (nil, nil). The caller of Encode is responsible for writing the correct NULL value or the length of the data written.

(oid uint32, formatCode int16, value any, buf []byte)

Source from the content-addressed store, hash-verified

1967// (nil, nil). The caller of Encode is responsible for writing the correct NULL value or the length of the data
1968// written.
1969func (m *Map) Encode(oid uint32, formatCode int16, value any, buf []byte) (newBuf []byte, err error) {
1970 if isNil, callNilDriverValuer := isNilDriverValuer(value); isNil {
1971 if callNilDriverValuer {
1972 newBuf, err = (&encodePlanDriverValuer{m: m, oid: oid, formatCode: formatCode}).Encode(value, buf)
1973 if err != nil {
1974 return nil, newEncodeError(value, m, oid, formatCode, err)
1975 }
1976
1977 return newBuf, nil
1978 } else {
1979 return nil, nil
1980 }
1981 }
1982
1983 plan := m.PlanEncode(oid, formatCode, value)
1984 if plan == nil {
1985 return nil, newEncodeError(value, m, oid, formatCode, errors.New("cannot find encode plan"))
1986 }
1987
1988 newBuf, err = plan.Encode(value, buf)
1989 if err != nil {
1990 return nil, newEncodeError(value, m, oid, formatCode, err)
1991 }
1992
1993 return newBuf, nil
1994}
1995
1996// SQLScanner returns a database/sql.Scanner for v. This is necessary for types like Array[T] and Range[T] where the
1997// type needs assistance from Map to implement the sql.Scanner interface. It is not necessary for types like Box that

Calls 4

PlanEncodeMethod · 0.95
isNilDriverValuerFunction · 0.85
newEncodeErrorFunction · 0.85
EncodeMethod · 0.65