VarInt.fromBuffer constructor

VarInt.fromBuffer(
  1. List<int> buf,
  2. int offset
)

Constructs a new VarInt with the value parsed from the specified offset of the given buffer.

@param buf the buffer containing the value @param offset the offset of the value

Implementation

VarInt.fromBuffer(List<int> buf, int offset) {
  var reader = ByteDataReader();
  reader.add(buf);
  int first = 0xFF & buf[offset];
  if (first < 253) {
    value = first;
    originallyEncodedSize = 1; // 1 data byte (8 bits)
  } else if (first == 253) {
    value = reader.readUint16(Endian.little); //Utils.readUint16(buf, offset + 1);
    originallyEncodedSize = 3; // 1 marker + 2 data bytes (16 bits)
  } else if (first == 254) {
    value = reader.readUint32(Endian.little); //Utils.readUint32(buf, offset + 1);
    originallyEncodedSize = 5; // 1 marker + 4 data bytes (32 bits)
  } else {
    value = reader.readInt64(Endian.little); // Utils.readInt64(buf, offset + 1);
    originallyEncodedSize = 9; // 1 marker + 8 data bytes (64 bits)
  }
}