MCPcopy Index your code
hub / github.com/lib/pq / encode

Function encode

encode.go:26–52  ·  view source on GitHub ↗
(x any, pgtypOid oid.Oid)

Source from the content-addressed store, hash-verified

24}
25
26func encode(x any, pgtypOid oid.Oid) ([]byte, error) {
27 switch v := x.(type) {
28 case int64:
29 return strconv.AppendInt(nil, v, 10), nil
30 case float64:
31 return strconv.AppendFloat(nil, v, 'f', -1, 64), nil
32 case []byte:
33 if v == nil {
34 return nil, nil
35 }
36 if pgtypOid == oid.T_bytea {
37 return encodeBytea(v), nil
38 }
39 return v, nil
40 case string:
41 if pgtypOid == oid.T_bytea {
42 return encodeBytea([]byte(v)), nil
43 }
44 return []byte(v), nil
45 case bool:
46 return strconv.AppendBool(nil, v), nil
47 case time.Time:
48 return formatTS(v), nil
49 default:
50 return nil, fmt.Errorf("pq: encode: unknown type for %T", v)
51 }
52}
53
54func decode(ps *parameterStatus, s []byte, typ oid.Oid, f format) (any, error) {
55 switch f {

Callers 5

TestEncodeByteaFunction · 0.85
BenchmarkEncodeFunction · 0.85
appendValueFunction · 0.85
binaryEncodeFunction · 0.85
execMethod · 0.85

Calls 2

encodeByteaFunction · 0.85
formatTSFunction · 0.85

Tested by 2

TestEncodeByteaFunction · 0.68
BenchmarkEncodeFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…