encodeList function

void encodeList(
  1. List list,
  2. LengthTrackingByteSink builder
)

Implementation

void encodeList(List list, LengthTrackingByteSink builder) {
  final subBuilder = LengthTrackingByteSink();
  for (final item in list) {
    _encodeToBuffer(item, subBuilder);
  }

  final length = subBuilder.length;
  if (length <= 55) {
    builder
      ..addByte(0xc0 + length)
      ..add(subBuilder.asBytes());
    return;
  } else {
    final encodedLength = unsignedIntToBytes(BigInt.from(length));

    builder
      ..addByte(0xf7 + encodedLength.length)
      ..add(encodedLength)
      ..add(subBuilder.asBytes());
    return;
  }
}