MCPcopy
hub / github.com/audreyt/ethercalc / encodeFrame

Function encodeFrame

packages/socketio-shim/src/framing.ts:60–73  ·  view source on GitHub ↗
(packet: Packet)

Source from the content-addressed store, hash-verified

58 * trim trailing ones only when strictly safe (no data and no endpoint).
59 */
60export function encodeFrame(packet: Packet): string {
61 const typePart = String(packet.type);
62 const idPart = packet.id === undefined ? '' : String(packet.id);
63 const endpointPart = packet.endpoint ?? '';
64 const dataPart = packet.data ?? '';
65
66 // Always emit at least `<type>:<id>:<endpoint>`. Append `:<data>` only if
67 // data is present — trailing empty segment is legal but noisy, and the
68 // reference parser is happy with either form.
69 if (dataPart === '') {
70 return `${typePart}:${idPart}:${endpointPart}`;
71 }
72 return `${typePart}:${idPart}:${endpointPart}:${dataPart}`;
73}
74
75/**
76 * Decode a raw wire string into a Packet, or return null for anything

Callers 9

translate.test.tsFile · 0.90
framing.test.tsFile · 0.90
adapter.test.tsFile · 0.90
startHeartbeatFunction · 0.90
closeSessionFunction · 0.90
acceptFunction · 0.90
handleXhrPollFunction · 0.90
nativeToSocketIoEventFunction · 0.90
wrapSocketIoEventFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected