MCPcopy
hub / github.com/di-sukharev/opencommit / createFrame

Method createFrame

out/cli.cjs:63297–63328  ·  view source on GitHub ↗
(opcode)

Source from the content-addressed store, hash-verified

63295 var WebsocketFrameSend = class {
63296 /**
63297 * @param {Buffer|undefined} data
63298 */
63299 constructor(data) {
63300 this.frameData = data;
63301 this.maskKey = crypto3.randomBytes(4);
63302 }
63303 createFrame(opcode) {
63304 const bodyLength = this.frameData?.byteLength ?? 0;
63305 let payloadLength = bodyLength;
63306 let offset = 6;
63307 if (bodyLength > maxUnsigned16Bit) {
63308 offset += 8;
63309 payloadLength = 127;
63310 } else if (bodyLength > 125) {
63311 offset += 2;
63312 payloadLength = 126;
63313 }
63314 const buffer = Buffer.allocUnsafe(bodyLength + offset);
63315 buffer[0] = buffer[1] = 0;
63316 buffer[0] |= 128;
63317 buffer[0] = (buffer[0] & 240) + opcode;
63318 buffer[offset - 4] = this.maskKey[0];
63319 buffer[offset - 3] = this.maskKey[1];
63320 buffer[offset - 2] = this.maskKey[2];
63321 buffer[offset - 1] = this.maskKey[3];
63322 buffer[1] = payloadLength;
63323 if (payloadLength === 126) {
63324 buffer.writeUInt16BE(bodyLength, 2);
63325 } else if (payloadLength === 127) {
63326 buffer[2] = buffer[3] = 0;
63327 buffer.writeUIntBE(bodyLength, 4, 6);
63328 }
63329 buffer[1] |= 128;
63330 for (let i3 = 0; i3 < bodyLength; i3++) {
63331 buffer[offset + i3] = this.frameData[i3] ^ this.maskKey[i3 % 4];

Callers 3

runMethod · 0.80
closeMethod · 0.80
sendMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected