(chunk)
| 512 | |
| 513 | const self: Parser<T> = { |
| 514 | feedSync(chunk) { |
| 515 | if (stashed !== undefined) return takeStashed() |
| 516 | if (spent) return failSync("parser is spent") |
| 517 | // Complete frames in a fresh chunk parse in place; only partial frames |
| 518 | // are ever copied into the buffer. |
| 519 | const direct = bufferEnd === bufferStart |
| 520 | let buf: Uint8Array |
| 521 | let pos: number |
| 522 | let end: number |
| 523 | if (direct) { |
| 524 | buf = chunk |
| 525 | pos = 0 |
| 526 | end = chunk.length |
| 527 | } else { |
| 528 | if (chunk.length > 0) { |
| 529 | const remaining = bufferEnd - bufferStart |
| 530 | const required = remaining + chunk.length |
| 531 | if (required > buffer.length) { |
| 532 | const next = new Uint8Array(Math.max(256, buffer.length * 2, required)) |
| 533 | next.set(buffer.subarray(bufferStart, bufferEnd)) |
| 534 | buffer = next |
| 535 | bufferStart = 0 |
| 536 | bufferEnd = remaining |
| 537 | } else if (bufferStart > 0) { |
| 538 | buffer.copyWithin(0, bufferStart, bufferEnd) |
| 539 | bufferStart = 0 |
| 540 | bufferEnd = remaining |
| 541 | } |
| 542 | buffer.set(chunk, bufferEnd) |
| 543 | bufferEnd += chunk.length |
| 544 | } |
| 545 | buf = buffer |
| 546 | pos = bufferStart |
| 547 | end = bufferEnd |
| 548 | } |
| 549 | const out: Array<T> = [] |
| 550 | const done = (): Array<T> => { |
| 551 | if (direct) { |
| 552 | if (pos < end) stashTail(chunk, pos) |
| 553 | } else { |
| 554 | bufferStart = pos |
| 555 | if (bufferStart === bufferEnd) bufferStart = bufferEnd = 0 |
| 556 | } |
| 557 | return out |
| 558 | } |
| 559 | const fail = (expected: string, input?: unknown): Array<T> => { |
| 560 | spent = true |
| 561 | const error = new Schema.SchemaError(new SchemaIssue.InvalidValue({ expected }, input, parseOptions)) |
| 562 | release() |
| 563 | if (out.length === 0) throw error |
| 564 | stashed = error |
| 565 | return out |
| 566 | } |
| 567 | while (true) { |
| 568 | // Use bigint only for frame lengths wider than six varint groups. |
| 569 | let frameLen = 0 |
| 570 | let headerLen = -1 |
| 571 | const buffered = end - pos |
nothing calls this directly
no test coverage detected