(data: Uint8Array)
| 64 | * the hand encoding is 10 lines and avoids a runtime dep in the hot path. |
| 65 | */ |
| 66 | export 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. |
no test coverage detected