encodeVarint function

Uint8List encodeVarint(
  1. int value
)

Encodes an integer as a varint

Implementation

Uint8List encodeVarint(int value) {
  if (value < 0) {
    throw ArgumentError('Cannot encode negative value');
  }

  final bytes = <int>[];
  do {
    int b = value & 0x7F;
    value >>= 7;
    if (value != 0) {
      b |= 0x80;
    }
    bytes.add(b);
  } while (value != 0);

  return Uint8List.fromList(bytes);
}