MCPcopy Create free account
hub / github.com/Snapchat/Valdi / encodeWsTextFrame

Function encodeWsTextFrame

npm_modules/cli/test/hermesClient.spec.ts:28–40  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

26}
27
28function encodeWsTextFrame(text: string): Buffer {
29 const payload = Buffer.from(text, 'utf8');
30 const len = payload.length;
31 const header = len < 126 ? Buffer.alloc(2) : Buffer.alloc(4);
32 header[0] = 0x81; // FIN + text opcode
33 if (len < 126) {
34 header[1] = len; // unmasked
35 } else {
36 header[1] = 126;
37 header.writeUInt16BE(len, 2);
38 }
39 return Buffer.concat([header, payload]);
40}
41
42function encodePingFrame(): Buffer {
43 const buf = Buffer.alloc(2);

Callers 1

Calls 2

fromMethod · 0.45
concatMethod · 0.45

Tested by

no test coverage detected