@tgsnake/core
Version:
Pure Telegram MTProto library for nodejs
42 lines (41 loc) • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Bytes = void 0;
const TLObject_js_1 = require("../TLObject.js");
const helpers_js_1 = require("../../../helpers.js");
const platform_node_js_1 = require("../../../platform.node.js");
class Bytes extends TLObject_js_1.TLObject {
static write(value) {
const length = platform_node_js_1.Buffer.byteLength(value);
if (length <= 253) {
return platform_node_js_1.Buffer.concat([
platform_node_js_1.Buffer.from([length]),
value,
platform_node_js_1.Buffer.alloc((0, helpers_js_1.mod)(-(length + 1), 4)),
]);
}
else {
return platform_node_js_1.Buffer.concat([
platform_node_js_1.Buffer.from([254]),
(0, helpers_js_1.bigintToBuffer)(BigInt(length), 3),
value,
platform_node_js_1.Buffer.alloc((0, helpers_js_1.mod)(-length, 4)),
]);
}
}
static async read(data, ..._args) {
let length = data.read(1)[0];
if (length <= 253) {
const x = data.read(length);
data.read((0, helpers_js_1.mod)(-(length + 1), 4));
return x;
}
else {
length = Number((0, helpers_js_1.bufferToBigint)(data.read(3)));
const x = data.read(length);
data.read((0, helpers_js_1.mod)(-length, 4));
return x;
}
}
}
exports.Bytes = Bytes;