Add takes an uid and adds it to the list of UIDs to be encoded.
(uid uint64)
| 105 | |
| 106 | // Add takes an uid and adds it to the list of UIDs to be encoded. |
| 107 | func (e *Encoder) Add(uid uint64) { |
| 108 | if e.pack == nil { |
| 109 | e.pack = &pb.UidPack{BlockSize: uint32(e.BlockSize)} |
| 110 | e.buf = new(bytes.Buffer) |
| 111 | } |
| 112 | if e.Alloc == nil { |
| 113 | e.Alloc = z.NewAllocator(1024, tagEncoder) |
| 114 | } |
| 115 | |
| 116 | size := len(e.uids) |
| 117 | if size > 0 && !match32MSB(e.uids[size-1], uid) { |
| 118 | e.packBlock() |
| 119 | e.uids = e.uids[:0] |
| 120 | } |
| 121 | |
| 122 | e.uids = append(e.uids, uid) |
| 123 | if len(e.uids) >= e.BlockSize { |
| 124 | e.packBlock() |
| 125 | e.uids = e.uids[:0] |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | // Done returns the final output of the encoder. This UidPack MUST BE FREED via a call to FreePack. |
| 130 | func (e *Encoder) Done() *pb.UidPack { |