Files
server_debian_macro/node_modules/tedious/lib/token/helpers.js

205 lines
24 KiB
JavaScript
Raw Normal View History

2025-02-18 22:59:07 +00:00
"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,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJSZXN1bHQiLCJjb25zdHJ1Y3RvciIsInZhbHVlIiwib2Zmc2V0IiwiZXhwb3J0cyIsIk5vdEVub3VnaERhdGFFcnJvciIsIkVycm9yIiwiYnl0ZUNvdW50IiwicmVhZFVJbnQ4IiwiYnVmIiwibGVuZ3RoIiwicmVhZFVJbnQxNkxFIiw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