EncodeFromBuffer is the same as Encode but it accepts a byte slice instead of a uint64 slice.
(buf []byte, blockSize int)
| 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 { |
| 403 | enc := Encoder{BlockSize: blockSize} |
| 404 | var prev uint64 |
| 405 | for len(buf) > 0 { |
| 406 | uid, n := binary.Uvarint(buf) |
| 407 | buf = buf[n:] |
| 408 | |
| 409 | next := prev + uid |
| 410 | enc.Add(next) |
| 411 | prev = next |
| 412 | } |
| 413 | return enc.Done() |
| 414 | } |
| 415 | |
| 416 | // ApproxLen would indicate the total number of UIDs in the pack. Can be used for int slice |
| 417 | // allocations. |