writeVarLong method

void writeVarLong(
  1. int value, {
  2. bool signed = false,
})
inherited

Write a single 8 byte variable length long.

Implementation

void writeVarLong(int value, {bool signed = false}) {
  if (signed || value < 0) {
    if (value < 0) {
      return writeVarLong(-2 * value - 1, signed: false);
    } else {
      return writeVarLong(2 * value, signed: false);
    }
  }
  while (true) {
    final byte = 0x7F & value;
    final nextValue = value >> 7;
    if (nextValue == 0) {
      writeByte(byte, signed: false);
      return;
    }
    writeByte(0x80 | byte, signed: false);
    value = nextValue;
  }
}