MCPcopy Create free account
hub / github.com/segmentio/encoding / customEncodeFuncOf

Function customEncodeFuncOf

proto/custom.go:33–62  ·  view source on GitHub ↗
(t reflect.Type)

Source from the content-addressed store, hash-verified

31}
32
33func customEncodeFuncOf(t reflect.Type) encodeFunc {
34 return func(b []byte, p unsafe.Pointer, flags flags) (int, error) {
35 if p != nil {
36 if m := reflect.NewAt(t, p).Interface().(customMessage); m != nil {
37 size := m.Size()
38
39 if flags.has(toplevel) {
40 if len(b) < size {
41 return 0, io.ErrShortBuffer
42 }
43 return m.MarshalTo(b)
44 }
45
46 vlen := sizeOfVarlen(size)
47 if len(b) < vlen {
48 return 0, io.ErrShortBuffer
49 }
50
51 n1, err := encodeVarint(b, uint64(size))
52 if err != nil {
53 return n1, err
54 }
55
56 n2, err := m.MarshalTo(b[n1:])
57 return n1 + n2, err
58 }
59 }
60 return 0, nil
61 }
62}
63
64func customDecodeFuncOf(t reflect.Type) decodeFunc {
65 return func(b []byte, p unsafe.Pointer, flags flags) (int, error) {

Callers 1

customCodecOfFunction · 0.85

Calls 5

sizeOfVarlenFunction · 0.85
encodeVarintFunction · 0.85
SizeMethod · 0.65
MarshalToMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…