getVarInt method

int getVarInt([
  1. Endian endian = Endian.little
])

Get next byte and return an int value based on the data length specified by this byte. The return value will between 0 and 264 - 1, inclusive.

Implementation

int getVarInt([Endian endian = Endian.little]) {
  ByteData bufferByteData = buffer.buffer.asByteData();
  int first = bufferByteData.getUint8(offset);
  int output;
  // 8 bit
  if (first < 0xfd) {
    output = first;
    offset += 1;
    // 16 bit
  } else if (first == 0xfd) {
    output = bufferByteData.getUint16(offset + 1, endian);
    offset += 3;

    // 32 bit
  } else if (first == 0xfe) {
    output = bufferByteData.getUint32(offset + 1, endian);
    offset += 5;

    // 64 bit
  } else {
    output = bufferByteData.getUint64(offset + 1, endian);
    offset += 9;
  }

  return output;
}