MCPcopy
hub / github.com/go-yaml/yaml / sequence

Method sequence

decode.go:729–765  ·  view source on GitHub ↗
(n *Node, out reflect.Value)

Source from the content-addressed store, hash-verified

727}
728
729func (d *decoder) sequence(n *Node, out reflect.Value) (good bool) {
730 l := len(n.Content)
731
732 var iface reflect.Value
733 switch out.Kind() {
734 case reflect.Slice:
735 out.Set(reflect.MakeSlice(out.Type(), l, l))
736 case reflect.Array:
737 if l != out.Len() {
738 failf("invalid array: want %d elements but got %d", out.Len(), l)
739 }
740 case reflect.Interface:
741 // No type hints. Will have to use a generic sequence.
742 iface = out
743 out = settableValueOf(make([]interface{}, l))
744 default:
745 d.terror(n, seqTag, out)
746 return false
747 }
748 et := out.Type().Elem()
749
750 j := 0
751 for i := 0; i < l; i++ {
752 e := reflect.New(et).Elem()
753 if ok := d.unmarshal(n.Content[i], e); ok {
754 out.Index(j).Set(e)
755 j++
756 }
757 }
758 if out.Kind() != reflect.Array {
759 out.Set(out.Slice(0, j))
760 }
761 if iface.IsValid() {
762 iface.Set(out)
763 }
764 return true
765}
766
767func (d *decoder) mapping(n *Node, out reflect.Value) (good bool) {
768 l := len(n.Content)

Callers 1

unmarshalMethod · 0.95

Calls 5

terrorMethod · 0.95
unmarshalMethod · 0.95
failfFunction · 0.85
settableValueOfFunction · 0.85
LenMethod · 0.80

Tested by

no test coverage detected