MCPcopy Index your code
hub / github.com/TanStack/router / encodeFrame

Function encodeFrame

packages/start-server-core/src/frame-protocol.ts:31–50  ·  view source on GitHub ↗
(
  type: FrameType,
  streamId: number,
  payload: Uint8Array,
)

Source from the content-addressed store, hash-verified

29 * Encodes a single frame with header and payload.
30 */
31export function encodeFrame(
32 type: FrameType,
33 streamId: number,
34 payload: Uint8Array,
35): Uint8Array {
36 const frame = new Uint8Array(FRAME_HEADER_SIZE + payload.length)
37 // Write header bytes directly to avoid DataView allocation per frame
38 // Frame format: [type:1][streamId:4 BE][length:4 BE]
39 frame[0] = type
40 frame[1] = (streamId >>> 24) & 0xff
41 frame[2] = (streamId >>> 16) & 0xff
42 frame[3] = (streamId >>> 8) & 0xff
43 frame[4] = streamId & 0xff
44 frame[5] = (payload.length >>> 24) & 0xff
45 frame[6] = (payload.length >>> 16) & 0xff
46 frame[7] = (payload.length >>> 8) & 0xff
47 frame[8] = payload.length & 0xff
48 frame.set(payload, FRAME_HEADER_SIZE)
49 return frame
50}
51
52/**
53 * Encodes a JSON frame (type 0, streamId 0).

Callers 5

encodeJSONFrameFunction · 0.70
encodeChunkFrameFunction · 0.70
encodeEndFrameFunction · 0.70
encodeErrorFrameFunction · 0.70

Calls 1

setMethod · 0.65

Tested by

no test coverage detected