MCPcopy Index your code
hub / github.com/vmihailenco/msgpack / DecodeInterface

Method DecodeInterface

decode.go:401–467  ·  view source on GitHub ↗

DecodeInterface decodes value into interface. It returns following types: - nil, - bool, - int8, int16, int32, int64, - uint8, uint16, uint32, uint64, - float32 and float64, - string, - []byte, - slices of any of the above, - maps of any of the above. DecodeInterface should be used only when you do

()

Source from the content-addressed store, hash-verified

399// you are decoding. For example, if you are decoding number it is better to use
400// DecodeInt64 for negative numbers and DecodeUint64 for positive numbers.
401func (d *Decoder) DecodeInterface() (interface{}, error) {
402 c, err := d.readCode()
403 if err != nil {
404 return nil, err
405 }
406
407 if msgpcode.IsFixedNum(c) {
408 return int8(c), nil
409 }
410 if msgpcode.IsFixedMap(c) {
411 err = d.s.UnreadByte()
412 if err != nil {
413 return nil, err
414 }
415 return d.decodeMapDefault()
416 }
417 if msgpcode.IsFixedArray(c) {
418 return d.decodeSlice(c)
419 }
420 if msgpcode.IsFixedString(c) {
421 return d.string(c)
422 }
423
424 switch c {
425 case msgpcode.Nil:
426 return nil, nil
427 case msgpcode.False, msgpcode.True:
428 return d.bool(c)
429 case msgpcode.Float:
430 return d.float32(c)
431 case msgpcode.Double:
432 return d.float64(c)
433 case msgpcode.Uint8:
434 return d.uint8()
435 case msgpcode.Uint16:
436 return d.uint16()
437 case msgpcode.Uint32:
438 return d.uint32()
439 case msgpcode.Uint64:
440 return d.uint64()
441 case msgpcode.Int8:
442 return d.int8()
443 case msgpcode.Int16:
444 return d.int16()
445 case msgpcode.Int32:
446 return d.int32()
447 case msgpcode.Int64:
448 return d.int64()
449 case msgpcode.Bin8, msgpcode.Bin16, msgpcode.Bin32:
450 return d.bytes(c, nil)
451 case msgpcode.Str8, msgpcode.Str16, msgpcode.Str32:
452 return d.string(c)
453 case msgpcode.Array16, msgpcode.Array32:
454 return d.decodeSlice(c)
455 case msgpcode.Map16, msgpcode.Map32:
456 err = d.s.UnreadByte()
457 if err != nil {
458 return nil, err

Callers 14

TestTypesFunction · 0.95
TestStringsBinFunction · 0.95
TestBinFunction · 0.95
TestUint64Function · 0.95
TestInt64Function · 0.95
TestFloat32Function · 0.95
TestFloat64Function · 0.95
TestInternedStringFunction · 0.95
TestResetDictFunction · 0.95

Calls 15

readCodeMethod · 0.95
decodeMapDefaultMethod · 0.95
decodeSliceMethod · 0.95
stringMethod · 0.95
boolMethod · 0.95
float32Method · 0.95
float64Method · 0.95
uint8Method · 0.95
uint16Method · 0.95
uint32Method · 0.95
uint64Method · 0.95
int8Method · 0.95

Tested by 13

TestTypesFunction · 0.76
TestStringsBinFunction · 0.76
TestBinFunction · 0.76
TestUint64Function · 0.76
TestInt64Function · 0.76
TestFloat32Function · 0.76
TestFloat64Function · 0.76
TestInternedStringFunction · 0.76
TestResetDictFunction · 0.76