"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Result = exports.NotEnoughDataError = void 0;
exports.readBVarByte = readBVarByte;
exports.readBVarChar = readBVarChar;
exports.readBigInt64LE = readBigInt64LE;
exports.readBigUInt64LE = readBigUInt64LE;
exports.readDoubleLE = readDoubleLE;
exports.readFloatLE = readFloatLE;
exports.readInt16LE = readInt16LE;
exports.readInt32LE = readInt32LE;
exports.readUInt16LE = readUInt16LE;
exports.readUInt24LE = readUInt24LE;
exports.readUInt32BE = readUInt32BE;
exports.readUInt32LE = readUInt32LE;
exports.readUInt40LE = readUInt40LE;
exports.readUInt8 = readUInt8;
exports.readUNumeric128LE = readUNumeric128LE;
exports.readUNumeric64LE = readUNumeric64LE;
exports.readUNumeric96LE = readUNumeric96LE;
exports.readUsVarByte = readUsVarByte;
exports.readUsVarChar = readUsVarChar;
class Result {
  constructor(value, offset) {
    this.value = value;
    this.offset = offset;
  }
}
exports.Result = Result;
class NotEnoughDataError extends Error {
  byteCount;
  constructor(byteCount) {
    super();
    this.byteCount = byteCount;
  }
}
exports.NotEnoughDataError = NotEnoughDataError;
function readUInt8(buf, offset) {
  offset = +offset;
  if (buf.length < offset + 1) {
    throw new NotEnoughDataError(offset + 1);
  }
  return new Result(buf.readUInt8(offset), offset + 1);
}
function readUInt16LE(buf, offset) {
  offset = +offset;
  if (buf.length < offset + 2) {
    throw new NotEnoughDataError(offset + 2);
  }
  return new Result(buf.readUInt16LE(offset), offset + 2);
}
function readInt16LE(buf, offset) {
  offset = +offset;
  if (buf.length < offset + 2) {
    throw new NotEnoughDataError(offset + 2);
  }
  return new Result(buf.readInt16LE(offset), offset + 2);
}
function readUInt24LE(buf, offset) {
  offset = +offset;
  if (buf.length < offset + 3) {
    throw new NotEnoughDataError(offset + 3);
  }
  return new Result(buf.readUIntLE(offset, 3), offset + 3);
}
function readUInt32LE(buf, offset) {
  offset = +offset;
  if (buf.length < offset + 4) {
    throw new NotEnoughDataError(offset + 4);
  }
  return new Result(buf.readUInt32LE(offset), offset + 4);
}
function readUInt32BE(buf, offset) {
  offset = +offset;
  if (buf.length < offset + 4) {
    throw new NotEnoughDataError(offset + 4);
  }
  return new Result(buf.readUInt32BE(offset), offset + 4);
}
function readUInt40LE(buf, offset) {
  offset = +offset;
  if (buf.length < offset + 5) {
    throw new NotEnoughDataError(offset + 5);
  }
  return new Result(buf.readUIntLE(offset, 5), offset + 5);
}
function readInt32LE(buf, offset) {
  offset = +offset;
  if (buf.length < offset + 4) {
    throw new NotEnoughDataError(offset + 4);
  }
  return new Result(buf.readInt32LE(offset), offset + 4);
}
function readBigUInt64LE(buf, offset) {
  offset = +offset;
  if (buf.length < offset + 8) {
    throw new NotEnoughDataError(offset + 8);
  }
  return new Result(buf.readBigUInt64LE(offset), offset + 8);
}
function readBigInt64LE(buf, offset) {
  offset = +offset;
  if (buf.length < offset + 8) {
    throw new NotEnoughDataError(offset + 8);
  }
  return new Result(buf.readBigInt64LE(offset), offset + 8);
}
function readFloatLE(buf, offset) {
  offset = +offset;
  if (buf.length < offset + 4) {
    throw new NotEnoughDataError(offset + 4);
  }
  return new Result(buf.readFloatLE(offset), offset + 4);
}
function readDoubleLE(buf, offset) {
  offset = +offset;
  if (buf.length < offset + 8) {
    throw new NotEnoughDataError(offset + 8);
  }
  return new Result(buf.readDoubleLE(offset), offset + 8);
}
function readBVarChar(buf, offset) {
  offset = +offset;
  let charCount;
  ({
    offset,
    value: charCount
  } = readUInt8(buf, offset));
  const byteLength = charCount * 2;
  if (buf.length < offset + byteLength) {
    throw new NotEnoughDataError(offset + byteLength);
  }
  return new Result(buf.toString('ucs2', offset, offset + byteLength), offset + byteLength);
}
function readBVarByte(buf, offset) {
  offset = +offset;
  let byteLength;
  ({
    offset,
    value: byteLength
  } = readUInt8(buf, offset));
  if (buf.length < offset + byteLength) {
    throw new NotEnoughDataError(offset + byteLength);
  }
  return new Result(buf.slice(offset, offset + byteLength), offset + byteLength);
}
function readUsVarChar(buf, offset) {
  offset = +offset;
  let charCount;
  ({
    offset,
    value: charCount
  } = readUInt16LE(buf, offset));
  const byteLength = charCount * 2;
  if (buf.length < offset + byteLength) {
    throw new NotEnoughDataError(offset + byteLength);
  }
  return new Result(buf.toString('ucs2', offset, offset + byteLength), offset + byteLength);
}
function readUsVarByte(buf, offset) {
  offset = +offset;
  let byteLength;
  ({
    offset,
    value: byteLength
  } = readUInt16LE(buf, offset));
  if (buf.length < offset + byteLength) {
    throw new NotEnoughDataError(offset + byteLength);
  }
  return new Result(buf.slice(offset, offset + byteLength), offset + byteLength);
}
function readUNumeric64LE(buf, offset) {
  offset = +offset;
  if (buf.length < offset + 8) {
    throw new NotEnoughDataError(offset + 8);
  }
  const low = buf.readUInt32LE(offset);
  const high = buf.readUInt32LE(offset + 4);
  return new Result(0x100000000 * high + low, offset + 8);
}
function readUNumeric96LE(buf, offset) {
  offset = +offset;
  if (buf.length < offset + 12) {
    throw new NotEnoughDataError(offset + 12);
  }
  const dword1 = buf.readUInt32LE(offset);
  const dword2 = buf.readUInt32LE(offset + 4);
  const dword3 = buf.readUInt32LE(offset + 8);
  return new Result(dword1 + 0x100000000 * dword2 + 0x100000000 * 0x100000000 * dword3, offset + 12);
}
function readUNumeric128LE(buf, offset) {
  offset = +offset;
  if (buf.length < offset + 16) {
    throw new NotEnoughDataError(offset + 16);
  }
  const dword1 = buf.readUInt32LE(offset);
  const dword2 = buf.readUInt32LE(offset + 4);
  const dword3 = buf.readUInt32LE(offset + 8);
  const dword4 = buf.readUInt32LE(offset + 12);
  return new Result(dword1 + 0x100000000 * dword2 + 0x100000000 * 0x100000000 * dword3 + 0x100000000 * 0x100000000 * 0x100000000 * dword4, offset + 16);
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 18520 characters]