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

Method encodeMessage

test/common/websocket-server.js:94–108  ·  view source on GitHub ↗
(message)

Source from the content-addressed store, hash-verified

92 }
93
94 encodeMessage(message) {
95 const msgBuffer = Buffer.from(message);
96 const length = msgBuffer.length;
97 const frame = [0x81];
98
99 if (length < 126) {
100 frame.push(length);
101 } else if (length < 65536) {
102 frame.push(126, (length >> 8) & 0xff, length & 0xff);
103 } else {
104 throw new Error('Message too long');
105 }
106
107 return Buffer.concat([Buffer.from(frame), msgBuffer]);
108 }
109}
110
111module.exports = WebSocketServer;

Callers 1

handleUpgradeMethod · 0.95

Calls 3

concatMethod · 0.80
fromMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected