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

Function decodeFuncMapAsSetOf

thrift/decode.go:311–358  ·  view source on GitHub ↗
(t reflect.Type, seen decodeFuncCache)

Source from the content-addressed store, hash-verified

309}
310
311func decodeFuncMapAsSetOf(t reflect.Type, seen decodeFuncCache) decodeFunc {
312 key, elem := t.Key(), t.Elem()
313 keyZero := reflect.Zero(key)
314 elemZero := reflect.Zero(elem)
315 typ := TypeOf(key)
316 dec := decodeFuncOf(key, seen)
317
318 return func(r Reader, v reflect.Value, flags flags) error {
319 s, err := r.ReadSet()
320 if err != nil {
321 return err
322 }
323
324 // See decodeFuncSliceOf for details about why this type conversion
325 // needs to be done.
326 switch s.Type {
327 case TRUE:
328 s.Type = BOOL
329 }
330
331 v.Set(reflect.MakeMapWithSize(t, int(s.Size)))
332
333 if s.Size == 0 {
334 return nil
335 }
336
337 // TODO: implement type conversions?
338 if typ != s.Type {
339 if flags.have(strict) {
340 return &TypeMismatch{item: "list item", Expect: typ, Found: s.Type}
341 }
342 return nil
343 }
344
345 tmp := reflect.New(key).Elem()
346 flags = flags.only(decodeFlags)
347
348 for i := range int(s.Size) {
349 if err := dec(r, tmp, flags); err != nil {
350 return with(dontExpectEOF(err), &decodeErrorSet{cause: s, index: i})
351 }
352 v.SetMapIndex(tmp, elemZero)
353 tmp.Set(keyZero)
354 }
355
356 return nil
357 }
358}
359
360type structDecoder struct {
361 fields []structDecoderField

Callers 1

decodeFuncMapOfFunction · 0.85

Calls 9

decodeFuncOfFunction · 0.85
withFunction · 0.85
dontExpectEOFFunction · 0.85
haveMethod · 0.80
onlyMethod · 0.80
TypeOfFunction · 0.70
KeyMethod · 0.65
ElemMethod · 0.65
ReadSetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…