encodeUnsigned static method

Uint8List encodeUnsigned(
  1. int value
)

Converts an ordinary integer into a list of bytes that contains an LEB128 unsigned integer. The size of the integer is decided automatically.

Implementation

static Uint8List encodeUnsigned(int value) {
  int size = (value.toRadixString(2).length / 7.0).ceil();
  List<int> parts = List.empty(growable: true);
  int i = 0;
  while (i < size) {
    int part = value & 0x7f;
    value >>= 7;
    parts.add(part);
    i += 1;
  }
  for (var i = 0; i < parts.length - 1; i++) parts[i] |= 0x80;
  return Uint8List.fromList(parts);
}