(n *Node, out reflect.Value)
| 765 | } |
| 766 | |
| 767 | func (d *decoder) mapping(n *Node, out reflect.Value) (good bool) { |
| 768 | l := len(n.Content) |
| 769 | if d.uniqueKeys { |
| 770 | nerrs := len(d.terrors) |
| 771 | for i := 0; i < l; i += 2 { |
| 772 | ni := n.Content[i] |
| 773 | for j := i + 2; j < l; j += 2 { |
| 774 | nj := n.Content[j] |
| 775 | if ni.Kind == nj.Kind && ni.Value == nj.Value { |
| 776 | d.terrors = append(d.terrors, fmt.Sprintf("line %d: mapping key %#v already defined at line %d", nj.Line, nj.Value, ni.Line)) |
| 777 | } |
| 778 | } |
| 779 | } |
| 780 | if len(d.terrors) > nerrs { |
| 781 | return false |
| 782 | } |
| 783 | } |
| 784 | switch out.Kind() { |
| 785 | case reflect.Struct: |
| 786 | return d.mappingStruct(n, out) |
| 787 | case reflect.Map: |
| 788 | // okay |
| 789 | case reflect.Interface: |
| 790 | iface := out |
| 791 | if isStringMap(n) { |
| 792 | out = reflect.MakeMap(d.stringMapType) |
| 793 | } else { |
| 794 | out = reflect.MakeMap(d.generalMapType) |
| 795 | } |
| 796 | iface.Set(out) |
| 797 | default: |
| 798 | d.terror(n, mapTag, out) |
| 799 | return false |
| 800 | } |
| 801 | |
| 802 | outt := out.Type() |
| 803 | kt := outt.Key() |
| 804 | et := outt.Elem() |
| 805 | |
| 806 | stringMapType := d.stringMapType |
| 807 | generalMapType := d.generalMapType |
| 808 | if outt.Elem() == ifaceType { |
| 809 | if outt.Key().Kind() == reflect.String { |
| 810 | d.stringMapType = outt |
| 811 | } else if outt.Key() == ifaceType { |
| 812 | d.generalMapType = outt |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | mergedFields := d.mergedFields |
| 817 | d.mergedFields = nil |
| 818 | |
| 819 | var mergeNode *Node |
| 820 | |
| 821 | mapIsNew := false |
| 822 | if out.IsNil() { |
| 823 | out.Set(reflect.MakeMap(outt)) |
| 824 | mapIsNew = true |
no test coverage detected