MCPcopy Index your code
hub / github.com/codeaashu/claude-code / encodeChunk

Function encodeChunk

src/upstreamproxy/relay.ts:66–81  ·  view source on GitHub ↗
(data: Uint8Array)

Source from the content-addressed store, hash-verified

64 * the hand encoding is 10 lines and avoids a runtime dep in the hot path.
65 */
66export function encodeChunk(data: Uint8Array): Uint8Array {
67 const len = data.length
68 // varint encoding of length — most chunks fit in 1–3 length bytes
69 const varint: number[] = []
70 let n = len
71 while (n > 0x7f) {
72 varint.push((n & 0x7f) | 0x80)
73 n >>>= 7
74 }
75 varint.push(n)
76 const out = new Uint8Array(1 + varint.length + len)
77 out[0] = 0x0a
78 out.set(varint, 1)
79 out.set(data, 1 + varint.length)
80 return out
81}
82
83/**
84 * Decode an UpstreamProxyChunk. Returns the data field, or null if malformed.

Callers 3

openTunnelFunction · 0.85
sendKeepaliveFunction · 0.85
forwardToWsFunction · 0.85

Calls 2

pushMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected