build method
Builds and returns the sorted index payload bytes.
The payload starts with the 4-byte little-endian format code, followed by
sorted records. For IndexSorted each record is
[varint digest length | digest bytes | varint offset]. For
MultihashIndexSorted each record is prefixed with the multihash code
as [varint multihash code | varint digest length | digest bytes | varint offset].
Implementation
Uint8List build() {
final sorted = List<_IndexEntry>.from(_entries)
..sort((a, b) => _compareBytes(a.digest, b.digest));
final builder = BytesBuilder();
final formatCode = multihashSorted ? 0x0401 : 0x0400;
builder.add(_encodeUint32le(formatCode));
for (final entry in sorted) {
final digest = entry.digest;
if (multihashSorted) {
builder.add(_encodeVarint(entry.multihashCode));
}
builder.add(_encodeVarint(digest.length));
builder.add(digest);
builder.add(_encodeVarint(entry.offset));
}
return builder.toBytes();
}