Add takes an uid and adds it to the list of UIDs to be encoded.
(uid uint64)
| 127 | |
| 128 | // Add takes an uid and adds it to the list of UIDs to be encoded. |
| 129 | func (e *Encoder) Add(uid uint64) { |
| 130 | if e.pack == nil { |
| 131 | e.pack = &UidPack{BlockSize: uint32(e.BlockSize)} |
| 132 | e.buf = new(bytes.Buffer) |
| 133 | } |
| 134 | if e.Alloc == nil { |
| 135 | e.Alloc = z.NewAllocator(1024) |
| 136 | e.Alloc.Tag = tagEncoder |
| 137 | } |
| 138 | |
| 139 | size := len(e.uids) |
| 140 | if size > 0 && !match32MSB(e.uids[size-1], uid) { |
| 141 | e.packBlock() |
| 142 | e.uids = e.uids[:0] |
| 143 | } |
| 144 | |
| 145 | e.uids = append(e.uids, uid) |
| 146 | if len(e.uids) >= e.BlockSize { |
| 147 | e.packBlock() |
| 148 | e.uids = e.uids[:0] |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // Done returns the final output of the encoder. This UidPack MUST BE FREED via a call to FreePack. |
| 153 | func (e *Encoder) Done() *UidPack { |