(value: unknown, label: string, maxBytes: number, allowEmpty = false)
| 1001 | } |
| 1002 | |
| 1003 | function utf8String(value: unknown, label: string, maxBytes: number, allowEmpty = false): string { |
| 1004 | if ( |
| 1005 | typeof value !== 'string' || |
| 1006 | (!allowEmpty && value.length === 0) || |
| 1007 | Buffer.byteLength(value, 'utf8') > maxBytes |
| 1008 | ) { |
| 1009 | throw invalidProtocolFrame(`Invalid ${label}`); |
| 1010 | } |
| 1011 | return value; |
| 1012 | } |
| 1013 | |
| 1014 | function id(value: unknown, label: string): string { |
| 1015 | const decoded = utf8String(value, label, ID_MAX_BYTES); |
no test coverage detected