MCPcopy Index your code
hub / github.com/nodejs/node / createFastTextFrame

Method createFastTextFrame

deps/undici/undici.js:15104–15133  ·  view source on GitHub ↗

* @param {Uint8Array} buffer

(buffer2)

Source from the content-addressed store, hash-verified

15102 * @param {Uint8Array} buffer
15103 */
15104 static createFastTextFrame(buffer2) {
15105 const maskKey = generateMask();
15106 const bodyLength = buffer2.length;
15107 for (let i = 0; i < bodyLength; ++i) {
15108 buffer2[i] ^= maskKey[i & 3];
15109 }
15110 let payloadLength = bodyLength;
15111 let offset = 6;
15112 if (bodyLength > maxUnsigned16Bit) {
15113 offset += 8;
15114 payloadLength = 127;
15115 } else if (bodyLength > 125) {
15116 offset += 2;
15117 payloadLength = 126;
15118 }
15119 const head = Buffer.allocUnsafeSlow(offset);
15120 head[0] = 128 | opcodes.TEXT;
15121 head[1] = payloadLength | 128;
15122 head[offset - 4] = maskKey[0];
15123 head[offset - 3] = maskKey[1];
15124 head[offset - 2] = maskKey[2];
15125 head[offset - 1] = maskKey[3];
15126 if (payloadLength === 126) {
15127 head.writeUInt16BE(bodyLength, 2);
15128 } else if (payloadLength === 127) {
15129 head[2] = head[3] = 0;
15130 head.writeUIntBE(bodyLength, 4, 6);
15131 }
15132 return [head, buffer2];
15133 }
15134 };
15135 module2.exports = {
15136 WebsocketFrameSend,

Callers 1

addMethod · 0.45

Calls 1

generateMaskFunction · 0.70

Tested by

no test coverage detected