encodeIndexedList<T> static method

Pointer<Uint8> encodeIndexedList<T>(
  1. List<T> items,
  2. void writeItem(
    1. RecordWriter w,
    2. T item
    ),
  3. Allocator alloc
)

Encodes a list of @HybridRecord objects with an O(1) offset index table.

Payload: [4B count][8B×n offset table][item bytes] — offsets from the payload start (after the outer 4-byte length prefix toNative prepends).

Counterpart: LazyRecordList.decode.

Implementation

static Pointer<Uint8> encodeIndexedList<T>(
  List<T> items,
  void Function(RecordWriter w, T item) writeItem,
  Allocator alloc,
) {
  final w = RecordWriter.acquire();
  RecordWriterBase.writeIndexedListPayload(w, items, writeItem);
  final ptr = w.toNative(alloc);
  RecordWriter.release(w);
  return ptr;
}