(n *Node, out reflect.Value)
| 563 | } |
| 564 | |
| 565 | func (d *decoder) scalar(n *Node, out reflect.Value) bool { |
| 566 | var tag string |
| 567 | var resolved interface{} |
| 568 | if n.indicatedString() { |
| 569 | tag = strTag |
| 570 | resolved = n.Value |
| 571 | } else { |
| 572 | tag, resolved = resolve(n.Tag, n.Value) |
| 573 | if tag == binaryTag { |
| 574 | data, err := base64.StdEncoding.DecodeString(resolved.(string)) |
| 575 | if err != nil { |
| 576 | failf("!!binary value contains invalid base64 data") |
| 577 | } |
| 578 | resolved = string(data) |
| 579 | } |
| 580 | } |
| 581 | if resolved == nil { |
| 582 | return d.null(out) |
| 583 | } |
| 584 | if resolvedv := reflect.ValueOf(resolved); out.Type() == resolvedv.Type() { |
| 585 | // We've resolved to exactly the type we want, so use that. |
| 586 | out.Set(resolvedv) |
| 587 | return true |
| 588 | } |
| 589 | // Perhaps we can use the value as a TextUnmarshaler to |
| 590 | // set its value. |
| 591 | if out.CanAddr() { |
| 592 | u, ok := out.Addr().Interface().(encoding.TextUnmarshaler) |
| 593 | if ok { |
| 594 | var text []byte |
| 595 | if tag == binaryTag { |
| 596 | text = []byte(resolved.(string)) |
| 597 | } else { |
| 598 | // We let any value be unmarshaled into TextUnmarshaler. |
| 599 | // That might be more lax than we'd like, but the |
| 600 | // TextUnmarshaler itself should bowl out any dubious values. |
| 601 | text = []byte(n.Value) |
| 602 | } |
| 603 | err := u.UnmarshalText(text) |
| 604 | if err != nil { |
| 605 | fail(err) |
| 606 | } |
| 607 | return true |
| 608 | } |
| 609 | } |
| 610 | switch out.Kind() { |
| 611 | case reflect.String: |
| 612 | if tag == binaryTag { |
| 613 | out.SetString(resolved.(string)) |
| 614 | return true |
| 615 | } |
| 616 | out.SetString(n.Value) |
| 617 | return true |
| 618 | case reflect.Interface: |
| 619 | out.Set(reflect.ValueOf(resolved)) |
| 620 | return true |
| 621 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: |
| 622 | // This used to work in v2, but it's very unfriendly. |
no test coverage detected