19 lines
770 B
JavaScript
Raw Permalink Normal View History

2025-06-21 23:30:33 +03:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encode = exports.getChunkHeader = void 0;
const constants_1 = require("./constants");
const getChunkHeader = (_data) => Buffer.alloc(0);
exports.getChunkHeader = getChunkHeader;
const encode = (data, options) => {
const { messageType } = options;
if (typeof messageType === 'string') {
throw new Error(`Unsupported message type ${messageType}`);
}
const encodedBuffer = Buffer.alloc(constants_1.HEADER_SIZE + data.length);
encodedBuffer.writeUInt16BE(messageType);
encodedBuffer.writeUInt32BE(data.length, 2);
data.copy(encodedBuffer, constants_1.HEADER_SIZE);
return encodedBuffer;
};
exports.encode = encode;
//# sourceMappingURL=encode.js.map