(args []super.Value)
| 28 | } |
| 29 | |
| 30 | func (u *Unflatten) Call(args []super.Value) super.Value { |
| 31 | val := args[0] |
| 32 | array, ok := super.TypeUnder(val.Type()).(*super.TypeArray) |
| 33 | if !ok { |
| 34 | return val |
| 35 | } |
| 36 | u.recordCache.reset() |
| 37 | root := u.recordCache.new() |
| 38 | u.types = u.types[:0] |
| 39 | u.values = u.values[:0] |
| 40 | for it := val.Bytes().Iter(); !it.Done(); { |
| 41 | bytes := it.Next() |
| 42 | path, typ, vb, err := u.parseElem(array.Type, bytes) |
| 43 | if err != nil { |
| 44 | return u.sctx.WrapError(err.Error(), super.NewValue(array.Type, bytes)) |
| 45 | } |
| 46 | if typ == nil { |
| 47 | continue |
| 48 | } |
| 49 | if removed := root.addPath(&u.recordCache, path); removed > 0 { |
| 50 | u.types = u.types[:len(u.types)-removed] |
| 51 | u.values = u.values[:len(u.values)-removed] |
| 52 | } |
| 53 | u.types = append(u.types, typ) |
| 54 | u.values = append(u.values, vb) |
| 55 | } |
| 56 | u.builder.Reset() |
| 57 | types, values := u.types, u.values |
| 58 | typ, err := root.build(u.sctx, &u.builder, func() (super.Type, scode.Bytes) { |
| 59 | typ, value := types[0], values[0] |
| 60 | types, values = types[1:], values[1:] |
| 61 | return typ, value |
| 62 | }) |
| 63 | if err != nil { |
| 64 | return u.sctx.WrapError(err.Error(), val) |
| 65 | } |
| 66 | return super.NewValue(typ, u.builder.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 { |
nothing calls this directly
no test coverage detected