(source: Buffer, bounds: BufferJsonValueBounds | null, cap = Number.POSITIVE_INFINITY)
| 583 | } |
| 584 | |
| 585 | function readJsonStringBuffer(source: Buffer, bounds: BufferJsonValueBounds | null, cap = Number.POSITIVE_INFINITY): string | undefined { |
| 586 | if (!bounds || bounds.kind !== 'string') return undefined |
| 587 | let out = '' |
| 588 | let segmentStart = bounds.start + 1 |
| 589 | for (let i = bounds.start + 1; i < bounds.end - 1 && out.length < cap; i++) { |
| 590 | const ch = source[i] |
| 591 | if (ch !== 0x5c) continue |
| 592 | |
| 593 | out = appendBufferJsonSegment(source, segmentStart, i, out, cap) |
| 594 | if (out.length >= cap) break |
| 595 | const next = source[++i] |
| 596 | if (next === undefined) break |
| 597 | if (next === 0x6e) out += '\n' |
| 598 | else if (next === 0x72) out += '\r' |
| 599 | else if (next === 0x74) out += '\t' |
| 600 | else if (next === 0x62) out += '\b' |
| 601 | else if (next === 0x66) out += '\f' |
| 602 | else if (next === 0x75 && i + 4 < bounds.end) { |
| 603 | const hex = source.subarray(i + 1, i + 5).toString('ascii') |
| 604 | const code = Number.parseInt(hex, 16) |
| 605 | if (Number.isFinite(code)) out += String.fromCharCode(code) |
| 606 | i += 4 |
| 607 | } else { |
| 608 | out += String.fromCharCode(next) |
| 609 | } |
| 610 | segmentStart = i + 1 |
| 611 | } |
| 612 | return appendBufferJsonSegment(source, segmentStart, bounds.end - 1, out, cap) |
| 613 | } |
| 614 | |
| 615 | function readJsonNumberFieldBuffer(source: Buffer, objectBounds: BufferJsonValueBounds | null, field: string): number | undefined { |
| 616 | if (!objectBounds || objectBounds.kind !== 'object') return undefined |
no test coverage detected