decode function

_DecodeOutputModel decode(
  1. Uint8List buffer, [
  2. int offset = 0
])

Decode varuint

Implementation

_DecodeOutputModel decode(Uint8List buffer, [int offset = 0]) {
  int bytes = 0, output;

  ByteData bufferByteData = buffer.buffer.asByteData();
  int first = bufferByteData.getUint8(offset);

  // 8 bit
  if (first < 0xfd) {
    bytes = 1;
    output = first;
    // 16 bit
  } else if (first == 0xfd) {
    bytes = 3;
    output = bufferByteData.getUint16(offset + 1, Endian.little);

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

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

  return _DecodeOutputModel(bytes, output);
}