EncodeFromBuffer is the same as Encode but it accepts a byte slice instead of a uint64 slice.
(buf []byte, blockSize int)
| 365 | |
| 366 | // EncodeFromBuffer is the same as Encode but it accepts a byte slice instead of a uint64 slice. |
| 367 | func EncodeFromBuffer(buf []byte, blockSize int) *UidPack { |
| 368 | enc := Encoder{BlockSize: blockSize} |
| 369 | var prev uint64 |
| 370 | for len(buf) > 0 { |
| 371 | uid, n := binary.Uvarint(buf) |
| 372 | buf = buf[n:] |
| 373 | |
| 374 | next := prev + uid |
| 375 | enc.Add(next) |
| 376 | prev = next |
| 377 | } |
| 378 | return enc.Done() |
| 379 | } |
| 380 | |
| 381 | // ApproxLen would indicate the total number of UIDs in the pack. Can be used for int slice |
| 382 | // allocations. |