encodeVarint function

Uint8List encodeVarint(
  1. int value
)

Implementation

Uint8List encodeVarint(int value) {
  final List<int> result = [];

  if (value < 0xFD) {
    result.add(value);
  } else if (value <= 0xFFFF) {
    result.addAll([0xFD, value & 0xFF, (value >> 8) & 0xFF]);
  } else if (value <= 0xFFFFFFFF) {
    result.addAll([
      0xFE,
      value & 0xFF,
      (value >> 8) & 0xFF,
      (value >> 16) & 0xFF,
      (value >> 24) & 0xFF
    ]);
  } else {
    result.addAll([
      0xFF,
      value & 0xFF,
      (value >> 8) & 0xFF,
      (value >> 16) & 0xFF,
      (value >> 24) & 0xFF,
      (value >> 32) & 0xFF,
      (value >> 40) & 0xFF,
      (value >> 48) & 0xFF,
      (value >> 56) & 0xFF,
    ]);
  }
  return Uint8List.fromList(result);
}