buildSegmentFromBatch function
Builds a segment from a WalBatch payload.
Runs in the background isolate (or inline on the web); it only touches pure byte codecs, never files or engine state.
Implementation
Uint8List buildSegmentFromBatch(Uint8List batch, int blockTargetSize) {
final builder = SegmentBuilder(blockTargetSize: blockTargetSize);
WalBatch.decode(batch, (kind, key, value) {
if (kind == WalOpKind.delete) {
builder.addTombstone(key);
} else {
final bytes = value!;
builder.add(key, Bytes.view(bytes, 0, bytes.length));
}
});
return builder.finish().asUint8List();
}