writeVarInt method

  1. @override
void writeVarInt(
  1. BigInt i
)
override

Implementation

@override
writeVarInt(BigInt i) {
  if (i.compareTo(BigInt.from(0xfd)) < 0) {
    // 8 bit
    writeUInt8(i.toInt());
  } else if (i.compareTo(BigInt.from(0xffff)) <= 0) {
    // 16 bit
    writeUInt8(0xfd);
    writeUInt16(i.toInt());
  } else if (i.compareTo(BigInt.from(0xffffffff)) <= 0) {
    // 32 bit
    writeUInt8(0xfe);
    writeUInt32(i.toInt());
  } else {
    // 64 bit
    writeUInt8(0xff);
    writeUInt64(i);
  }
}