(inner super.Type, vb scode.Bytes)
| 67 | } |
| 68 | |
| 69 | func (u *Unflatten) parseElem(inner super.Type, vb scode.Bytes) (field.Path, super.Type, scode.Bytes, error) { |
| 70 | if union, ok := super.TypeUnder(inner).(*super.TypeUnion); ok { |
| 71 | inner, vb = union.Untag(vb) |
| 72 | } |
| 73 | typ := super.TypeRecordOf(inner) |
| 74 | if typ == nil || len(typ.Fields) != 2 { |
| 75 | return nil, nil, nil, nil |
| 76 | } |
| 77 | nkey, ok := typ.IndexOfField("key") |
| 78 | if !ok { |
| 79 | return nil, nil, nil, nil |
| 80 | } |
| 81 | |
| 82 | vtyp, ok := typ.TypeOfField("value") |
| 83 | if !ok { |
| 84 | return nil, nil, nil, nil |
| 85 | } |
| 86 | it := scode.NewRecordIter(vb, 0) |
| 87 | kbytes, _ := it.Next(false) |
| 88 | vbytes, _ := it.Next(false) |
| 89 | if nkey == 1 { |
| 90 | kbytes, vbytes = vbytes, kbytes |
| 91 | } |
| 92 | ktyp := typ.Fields[nkey].Type |
| 93 | if ktyp.ID() == super.IDString { |
| 94 | u.path = append(u.path[:0], super.DecodeString(kbytes)) |
| 95 | return u.path, vtyp, vbytes, nil |
| 96 | } |
| 97 | if a, ok := super.TypeUnder(ktyp).(*super.TypeArray); ok && a.Type.ID() == super.IDString { |
| 98 | return u.decodeKey(kbytes), vtyp, vbytes, nil |
| 99 | } |
| 100 | return nil, nil, nil, fmt.Errorf("invalid key type %s: expected either string or [string]", sup.FormatType(ktyp)) |
| 101 | } |
| 102 | |
| 103 | func (u *Unflatten) decodeKey(b scode.Bytes) field.Path { |
| 104 | u.path = u.path[:0] |
no test coverage detected