read static method

int read(
  1. ByteData buffer,
  2. int offset
)

Read variable integer from byte data

Implementation

static int read(ByteData buffer, int offset) {
  final firstByte = buffer.getUint8(offset);

  if (firstByte < 0xFD) {
    return firstByte;
  } else if (firstByte == 0xFD) {
    return buffer.getUint16(offset + 1, Endian.little);
  } else if (firstByte == 0xFE) {
    return buffer.getUint32(offset + 1, Endian.little);
  } else {
    // 0xFF - 64-bit int, but we'll use 32-bit for now
    final low = buffer.getUint32(offset + 1, Endian.little);
    final high = buffer.getUint32(offset + 5, Endian.little);
    if (high != 0) {
      throw WireException('64-bit integers not supported');
    }
    return low;
  }
}