encode method

Uint8List encode()

Encodes the strings chunk to a Uint8List.

Implementation

Uint8List encode() {
  int totalSize = 4;

  final List<Uint8List> encodedStrings = <Uint8List>[];
  for (final Information stringInfo in strings) {
    final Uint8List encoded = stringInfo.encode();
    encodedStrings.add(encoded);
    totalSize += encoded.length;
  }

  final ByteData data = ByteData(totalSize);

  data.setUint32(0, numEntries);

  int offset = 4;
  for (final Uint8List encodedString in encodedStrings) {
    for (int i = 0; i < encodedString.length; i++) {
      data.setUint8(offset, encodedString[i]);
      offset++;
    }
  }

  return data.buffer.asUint8List();
}