DecodeInterfaceLoose is like DecodeInterface except that: - int8, int16, and int32 are converted to int64, - uint8, uint16, and uint32 are converted to uint64, - float32 is converted to float64. - []byte is converted to string.
()
| 472 | // - float32 is converted to float64. |
| 473 | // - []byte is converted to string. |
| 474 | func (d *Decoder) DecodeInterfaceLoose() (interface{}, error) { |
| 475 | c, err := d.readCode() |
| 476 | if err != nil { |
| 477 | return nil, err |
| 478 | } |
| 479 | |
| 480 | if msgpcode.IsFixedNum(c) { |
| 481 | return int64(int8(c)), nil |
| 482 | } |
| 483 | if msgpcode.IsFixedMap(c) { |
| 484 | err = d.s.UnreadByte() |
| 485 | if err != nil { |
| 486 | return nil, err |
| 487 | } |
| 488 | return d.decodeMapDefault() |
| 489 | } |
| 490 | if msgpcode.IsFixedArray(c) { |
| 491 | return d.decodeSlice(c) |
| 492 | } |
| 493 | if msgpcode.IsFixedString(c) { |
| 494 | return d.string(c) |
| 495 | } |
| 496 | |
| 497 | switch c { |
| 498 | case msgpcode.Nil: |
| 499 | return nil, nil |
| 500 | case msgpcode.False, msgpcode.True: |
| 501 | return d.bool(c) |
| 502 | case msgpcode.Float, msgpcode.Double: |
| 503 | return d.float64(c) |
| 504 | case msgpcode.Uint8, msgpcode.Uint16, msgpcode.Uint32, msgpcode.Uint64: |
| 505 | return d.uint(c) |
| 506 | case msgpcode.Int8, msgpcode.Int16, msgpcode.Int32, msgpcode.Int64: |
| 507 | return d.int(c) |
| 508 | case msgpcode.Str8, msgpcode.Str16, msgpcode.Str32, |
| 509 | msgpcode.Bin8, msgpcode.Bin16, msgpcode.Bin32: |
| 510 | return d.string(c) |
| 511 | case msgpcode.Array16, msgpcode.Array32: |
| 512 | return d.decodeSlice(c) |
| 513 | case msgpcode.Map16, msgpcode.Map32: |
| 514 | err = d.s.UnreadByte() |
| 515 | if err != nil { |
| 516 | return nil, err |
| 517 | } |
| 518 | return d.decodeMapDefault() |
| 519 | case msgpcode.FixExt1, msgpcode.FixExt2, msgpcode.FixExt4, msgpcode.FixExt8, msgpcode.FixExt16, |
| 520 | msgpcode.Ext8, msgpcode.Ext16, msgpcode.Ext32: |
| 521 | return d.decodeInterfaceExt(c) |
| 522 | } |
| 523 | |
| 524 | return 0, fmt.Errorf("msgpack: unknown code %x decoding interface{}", c) |
| 525 | } |
| 526 | |
| 527 | // Skip skips next value. |
| 528 | func (d *Decoder) Skip() error { |
no test coverage detected