encode static method
Uint8List
encode({
- required Schema schema,
- required Map<
String, dynamic> values, - required MvccTupleHeader header,
Implementation
static Uint8List encode({
required Schema schema,
required Map<String, dynamic> values,
required MvccTupleHeader header,
}) {
final cols = schema.columns;
final nullBitmapSize = (cols.length + 7) ~/ 8;
// Phase 1: encode column bytes, build null bitmap
final nullBitmap = Uint8List(nullBitmapSize);
final colBuffers = <Uint8List?>[];
for (int i = 0; i < cols.length; i++) {
final col = cols[i];
final raw = values[col.name];
if (raw == null) {
// Set null bit
nullBitmap[i >> 3] |= (1 << (i & 7));
colBuffers.add(null);
} else {
colBuffers.add(_encodeColumn(col.type, raw));
}
}
// Phase 2: compute total size
int totalSize = MvccTupleHeader.size + nullBitmapSize;
for (final cb in colBuffers) {
if (cb != null) totalSize += cb.length;
}
// Phase 3: assemble
final out = Uint8List(totalSize);
final bd = ByteData.sublistView(out);
header.encode(bd);
int pos = MvccTupleHeader.size;
out.setRange(pos, pos + nullBitmapSize, nullBitmap);
pos += nullBitmapSize;
for (final cb in colBuffers) {
if (cb != null) {
out.setRange(pos, pos + cb.length, cb);
pos += cb.length;
}
}
return out;
}