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

Method Encode

thrift/encode.go:32–50  ·  view source on GitHub ↗
(v any)

Source from the content-addressed store, hash-verified

30}
31
32func (e *Encoder) Encode(v any) error {
33 t := reflect.TypeOf(v)
34 cache, _ := encoderCache.Load().(map[typeID]encodeFunc)
35 encode := cache[makeTypeID(t)]
36
37 if encode == nil {
38 encode = encodeFuncOf(t, make(encodeFuncCache))
39
40 newCache := make(map[typeID]encodeFunc, len(cache)+1)
41 newCache[makeTypeID(t)] = encode
42 for k, v := range cache {
43 newCache[k] = v
44 }
45
46 encoderCache.Store(newCache)
47 }
48
49 return encode(e.w, reflect.ValueOf(v), e.f)
50}
51
52func (e *Encoder) Reset(w Writer) {
53 e.w = w

Callers 2

benchmarkMarshalFunction · 0.95
MarshalFunction · 0.95

Calls 2

makeTypeIDFunction · 0.85
encodeFuncOfFunction · 0.85

Tested by 1

benchmarkMarshalFunction · 0.76