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
()
| 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. |
| 401 | func (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 |