encodeVarInt7 static method

int encodeVarInt7(
  1. int n
)

Encodes a varInt7.

Implementation

static int encodeVarInt7(int n) {
  if (n < -64 || n > 63) {
    throw ArgumentError('Value is out of range for varInt7: $n');
  }

  final signBit = (n < 0) ? 1 : 0;
  final absValue = (n < 0) ? -n : n;

  final encoded = (signBit << 6) | (absValue & 0x3F);
  return encoded;
}