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

Function encodeFrameHybi17

lib/internal/debugger/inspect_client.js:66–101  ·  view source on GitHub ↗
(payload)

Source from the content-addressed store, hash-verified

64}
65
66function encodeFrameHybi17(payload) {
67 const dataLength = payload.length;
68
69 let singleByteLength;
70 let additionalLength;
71 if (dataLength > kMaxTwoBytePayloadLength) {
72 singleByteLength = kEightBytePayloadLengthField;
73 additionalLength = Buffer.alloc(8);
74 let remaining = dataLength;
75 for (let i = 0; i < 8; ++i) {
76 additionalLength[7 - i] = remaining & 0xFF;
77 remaining >>= 8;
78 }
79 } else if (dataLength > kMaxSingleBytePayloadLength) {
80 singleByteLength = kTwoBytePayloadLengthField;
81 additionalLength = Buffer.alloc(2);
82 additionalLength[0] = (dataLength & 0xFF00) >> 8;
83 additionalLength[1] = dataLength & 0xFF;
84 } else {
85 additionalLength = new FastBuffer();
86 singleByteLength = dataLength;
87 }
88
89 const header = Buffer.from([
90 kFinalBit | kOpCodeText,
91 kMaskBit | singleByteLength,
92 ]);
93
94 const mask = Buffer.alloc(4);
95 const masked = Buffer.alloc(dataLength);
96 for (let i = 0; i < dataLength; ++i) {
97 masked[i] = payload[i] ^ mask[i % kMaskingKeyWidthInBytes];
98 }
99
100 return Buffer.concat([header, additionalLength, mask, masked]);
101}
102
103function decodeFrameHybi17(data) {
104 const dataAvailable = data.length;

Callers 1

callMethodMethod · 0.85

Calls 3

allocMethod · 0.80
concatMethod · 0.80
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…