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

Function createFrame

benchmark/websocket/simple.js:17–42  ·  view source on GitHub ↗
(data, opcode)

Source from the content-addressed store, hash-verified

15const bench = common.createBenchmark(main, configs);
16
17function createFrame(data, opcode) {
18 let infoLength = 2;
19 let payloadLength = data.length;
20
21 if (payloadLength >= 65536) {
22 infoLength += 8;
23 payloadLength = 127;
24 } else if (payloadLength > 125) {
25 infoLength += 2;
26 payloadLength = 126;
27 }
28
29 const info = Buffer.alloc(infoLength);
30
31 info[0] = opcode | 0x80;
32 info[1] = payloadLength;
33
34 if (payloadLength === 126) {
35 info.writeUInt16BE(data.length, 2);
36 } else if (payloadLength === 127) {
37 info[2] = info[3] = 0;
38 info.writeUIntBE(data.length, 4, 6);
39 }
40
41 return Buffer.concat([info, data]);
42}
43
44function main(conf) {
45 const frame = createFrame(Buffer.alloc(conf.size).fill('.'), conf.useBinary === 'true' ? 2 : 1);

Callers 1

mainFunction · 0.70

Calls 2

allocMethod · 0.80
concatMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…