encode static method

Encodes a sequence of length-value.

Returns a sequence of bytes that contains each of the items in order. Each of those items is represented by a length followed by the bytes of the item. The length is always four bytes: a big-endian unsigned 32-bit integer.

Implementation

static Uint8List encode(Iterable<BinaryLengthValue> items) {
  final bytes = <int>[];

  for (final chunk in items) {
    // Chunk length (4-byte big-endian)
    final n = chunk._dataBytes.length;
    bytes
      ..add((n >> 24) & 0xFF)
      ..add((n >> 16) & 0xFF)
      ..add((n >> 8) & 0xFF)
      ..add((n >> 0) & 0xFF)
      ..addAll(chunk._dataBytes);
  }

  return Uint8List.fromList(bytes);
}