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

Method Decode

thrift/decode.go:46–73  ·  view source on GitHub ↗
(v any)

Source from the content-addressed store, hash-verified

44}
45
46func (d *Decoder) Decode(v any) error {
47 t := reflect.TypeOf(v)
48 p := reflect.ValueOf(v)
49
50 if t.Kind() != reflect.Ptr {
51 panic("thrift.(*Decoder).Decode: expected pointer type but got " + t.String())
52 }
53
54 t = t.Elem()
55 p = p.Elem()
56
57 cache, _ := decoderCache.Load().(map[typeID]decodeFunc)
58 decode := cache[makeTypeID(t)]
59
60 if decode == nil {
61 decode = decodeFuncOf(t, make(decodeFuncCache))
62
63 newCache := make(map[typeID]decodeFunc, len(cache)+1)
64 newCache[makeTypeID(t)] = decode
65 for k, v := range cache {
66 newCache[k] = v
67 }
68
69 decoderCache.Store(newCache)
70 }
71
72 return decode(d.r, p, d.f)
73}
74
75func (d *Decoder) Reset(r Reader) {
76 d.r = r

Callers 3

TestDecodeEOFFunction · 0.95
benchmarkUnmarshalFunction · 0.95
UnmarshalFunction · 0.45

Calls 5

makeTypeIDFunction · 0.85
decodeFuncOfFunction · 0.85
KindMethod · 0.65
StringMethod · 0.65
ElemMethod · 0.65

Tested by 2

TestDecodeEOFFunction · 0.76
benchmarkUnmarshalFunction · 0.76