decodeObject decodes a object value.
(ods *objectDecodeState, obj reflect.Value, encoded wire.Object)
| 512 | |
| 513 | // decodeObject decodes a object value. |
| 514 | func (ds *decodeState) decodeObject(ods *objectDecodeState, obj reflect.Value, encoded wire.Object) { |
| 515 | switch x := encoded.(type) { |
| 516 | case wire.Nil: // Fast path: first. |
| 517 | // We leave obj alone here. That's because if obj represents an |
| 518 | // interface, it may have been imbued with type information in |
| 519 | // decodeInterface, and we don't want to destroy that. |
| 520 | case *wire.Ref: |
| 521 | // Nil pointers may be encoded in a "forceValue" context. For |
| 522 | // those we just leave it alone as the value will already be |
| 523 | // correct (nil). |
| 524 | if id := objectID(x.Root); id == 0 { |
| 525 | return |
| 526 | } |
| 527 | |
| 528 | // Note that if this is a map type, we go through a level of |
| 529 | // indirection to allow for map aliasing. |
| 530 | if obj.Kind() == reflect.Map { |
| 531 | v := ds.register(x, obj.Type()) |
| 532 | if v.IsNil() { |
| 533 | // Note that we don't want to clobber the map |
| 534 | // if has already been decoded by decodeMap. We |
| 535 | // just make it so that we have a consistent |
| 536 | // reference when that eventually does happen. |
| 537 | v.Set(reflect.MakeMap(v.Type())) |
| 538 | } |
| 539 | obj.Set(v) |
| 540 | return |
| 541 | } |
| 542 | |
| 543 | // Normal assignment: authoritative only if no dots. |
| 544 | v := ds.register(x, obj.Type().Elem()) |
| 545 | obj.Set(reflectValueRWAddr(v)) |
| 546 | case wire.Bool: |
| 547 | obj.SetBool(bool(x)) |
| 548 | case wire.Int: |
| 549 | obj.SetInt(int64(x)) |
| 550 | if obj.Int() != int64(x) { |
| 551 | Failf("signed integer truncated from %v to %v", int64(x), obj.Int()) |
| 552 | } |
| 553 | case wire.Uint: |
| 554 | obj.SetUint(uint64(x)) |
| 555 | if obj.Uint() != uint64(x) { |
| 556 | Failf("unsigned integer truncated from %v to %v", uint64(x), obj.Uint()) |
| 557 | } |
| 558 | case wire.Float32: |
| 559 | obj.SetFloat(float64(x)) |
| 560 | case wire.Float64: |
| 561 | obj.SetFloat(float64(x)) |
| 562 | if !isFloatEq(obj.Float(), float64(x)) { |
| 563 | Failf("floating point number truncated from %v to %v", float64(x), obj.Float()) |
| 564 | } |
| 565 | case *wire.Complex64: |
| 566 | obj.SetComplex(complex128(*x)) |
| 567 | case *wire.Complex128: |
| 568 | obj.SetComplex(complex128(*x)) |
| 569 | if !isComplexEq(obj.Complex(), complex128(*x)) { |
| 570 | Failf("complex number truncated from %v to %v", complex128(*x), obj.Complex()) |
| 571 | } |
no test coverage detected