Encode takes in a list of uids and a block size. It would pack these uids into blocks of the given size, with the last block having fewer uids. Within each block, it stores the first uid as base. For each next uid, a delta = uids[i] - uids[i-1] is stored. Protobuf uses Varint encoding, as mentioned
(uids []uint64, blockSize int)
| 391 | // bytes. Our benchmarks on artificial data show compressed size to be 13% of the original. This |
| 392 | // mechanism is a LOT simpler to understand and if needed, debug. |
| 393 | func Encode(uids []uint64, blockSize int) *pb.UidPack { |
| 394 | enc := Encoder{BlockSize: blockSize} |
| 395 | for _, uid := range uids { |
| 396 | enc.Add(uid) |
| 397 | } |
| 398 | return enc.Done() |
| 399 | } |
| 400 | |
| 401 | // EncodeFromBuffer is the same as Encode but it accepts a byte slice instead of a uint64 slice. |
| 402 | func EncodeFromBuffer(buf []byte, blockSize int) *pb.UidPack { |