| 120 | // messages while a low-volume one stays small. A single oversized message |
| 121 | // grows its buffer beyond the pool without raising the pool itself. |
| 122 | const append = (chunk: Uint8Array): void => { |
| 123 | if (end + chunk.length > buffer.length) { |
| 124 | const pending = end - start |
| 125 | if (bufferSize < maxBufferSize) bufferSize *= 2 |
| 126 | let capacity = bufferSize |
| 127 | while (capacity < pending + chunk.length) capacity *= 2 |
| 128 | const next = new Uint8Array(capacity) |
| 129 | next.set(buffer.subarray(start, end)) |
| 130 | buffer = next |
| 131 | store = next.buffer |
| 132 | start = 0 |
| 133 | end = pending |
| 134 | } |
| 135 | buffer.set(chunk, end) |
| 136 | end += chunk.length |
| 137 | } |
| 138 | |
| 139 | const parser: Parser<A> = { |
| 140 | readField: options?.readField, |