(value: unknown, label: string, maxBytes: number, allowEmpty = false)
| 647 | } |
| 648 | |
| 649 | function boundedText(value: unknown, label: string, maxBytes: number, allowEmpty = false): string { |
| 650 | if (typeof value !== 'string' || (!allowEmpty && value.length === 0)) { |
| 651 | throw invalidProtocolFrame(`Invalid ${label}`); |
| 652 | } |
| 653 | if (Buffer.byteLength(value, 'utf8') > maxBytes) { |
| 654 | throw invalidProtocolFrame(`Invalid ${label}`); |
| 655 | } |
| 656 | return value; |
| 657 | } |
| 658 | |
| 659 | function boundedIngestText(value: unknown, label: string, maxBytes: number): string { |
| 660 | const text = boundedText(value, label, maxBytes); |
no test coverage detected