getVariableEncInt method

Tuple2<BigInt, int> getVariableEncInt(
  1. int startOffset
)

Implementation

Tuple2<BigInt, int> getVariableEncInt(int startOffset) {
  int firstByte = getUint8(startOffset);
  if (firstByte < 0xfb) {
    return Tuple2(BigInt.from(firstByte), 1);
  }

  if (firstByte == 0xfc) {
    String radix =
        getUint8(startOffset + 2).toRadixString(16).padLeft(2, '0') +
            getUint8(startOffset + 1).toRadixString(16).padLeft(2, '0');

    return Tuple2(BigInt.parse(radix, radix: 16), 3);
  }

  if (firstByte == 0xfd) {
    String radix =
        getUint8(startOffset + 3).toRadixString(16).padLeft(2, '0') +
            getUint8(startOffset + 2).toRadixString(16).padLeft(2, '0') +
            getUint8(startOffset + 1).toRadixString(16).padLeft(2, '0');

    return Tuple2(BigInt.parse(radix, radix: 16), 4);
  }

  if (firstByte == 0xfe) {
    String radix =
        getUint8(startOffset + 8).toRadixString(16).padLeft(2, '0') +
            getUint8(startOffset + 7).toRadixString(16).padLeft(2, '0') +
            getUint8(startOffset + 6).toRadixString(16).padLeft(2, '0') +
            getUint8(startOffset + 5).toRadixString(16).padLeft(2, '0') +
            getUint8(startOffset + 4).toRadixString(16).padLeft(2, '0') +
            getUint8(startOffset + 3).toRadixString(16).padLeft(2, '0') +
            getUint8(startOffset + 2).toRadixString(16).padLeft(2, '0') +
            getUint8(startOffset + 1).toRadixString(16).padLeft(2, '0');

    return Tuple2(BigInt.parse(radix, radix: 16), 9);
  }

  throw MySQLProtocolException(
      "Wrong first byte, while decoding getVariableEncInt");
}