decodeInterface decodes an interface value.
(ods *objectDecodeState, obj reflect.Value, encoded *wire.Interface)
| 468 | |
| 469 | // decodeInterface decodes an interface value. |
| 470 | func (ds *decodeState) decodeInterface(ods *objectDecodeState, obj reflect.Value, encoded *wire.Interface) { |
| 471 | if _, ok := encoded.Type.(wire.TypeSpecNil); ok { |
| 472 | // Special case; the nil object. Just decode directly, which |
| 473 | // will read nil from the wire (if encoded correctly). |
| 474 | ds.decodeObject(ods, obj, encoded.Value) |
| 475 | return |
| 476 | } |
| 477 | |
| 478 | // We now need to resolve the actual type. |
| 479 | typ := ds.findType(encoded.Type) |
| 480 | |
| 481 | // We need to imbue type information here, then we can proceed to |
| 482 | // decode normally. In order to avoid issues with setting value-types, |
| 483 | // we create a new non-interface version of this object. We will then |
| 484 | // set the interface object to be equal to whatever we decode. |
| 485 | origObj := obj |
| 486 | obj = reflect.New(typ).Elem() |
| 487 | defer origObj.Set(obj) |
| 488 | |
| 489 | // With the object now having sufficient type information to actually |
| 490 | // have Set called on it, we can proceed to decode the value. |
| 491 | ds.decodeObject(ods, obj, encoded.Value) |
| 492 | } |
| 493 | |
| 494 | // isFloatEq determines if x and y represent the same value. |
| 495 | func isFloatEq(x float64, y float64) bool { |
no test coverage detected