| 74 | } |
| 75 | |
| 76 | func (d *DynamicEncoder) Encode() (ID, uint64, error) { |
| 77 | var group errgroup.Group |
| 78 | d.tagEnc = &Uint32Encoder{vals: d.tags} |
| 79 | if len(d.values) > 1 { |
| 80 | d.tagEnc.Encode(&group) |
| 81 | } |
| 82 | for _, val := range d.values { |
| 83 | val.Encode(&group) |
| 84 | } |
| 85 | if err := group.Wait(); err != nil { |
| 86 | return 0, 0, err |
| 87 | } |
| 88 | if len(d.values) == 1 { |
| 89 | off, id := d.values[0].Metadata(d.cctx, 0) |
| 90 | return id, off, nil |
| 91 | } |
| 92 | values := make([]ID, 0, len(d.values)) |
| 93 | off, tags := d.tagEnc.Segment(0) |
| 94 | for _, val := range d.values { |
| 95 | var id ID |
| 96 | off, id = val.Metadata(d.cctx, off) |
| 97 | values = append(values, id) |
| 98 | } |
| 99 | return d.cctx.enter(&Dynamic{ |
| 100 | Tags: tags, |
| 101 | Values: values, |
| 102 | Length: d.len, |
| 103 | }), off, nil |
| 104 | } |
| 105 | |
| 106 | func (d *DynamicEncoder) Emit(w io.Writer) error { |
| 107 | if len(d.values) > 1 { |