| 668 | ?.prototype?.utf8Slice |
| 669 | |
| 670 | const decodeUtf8 = (bytes: Uint8Array, offset: number, size: number): string => { |
| 671 | if (size <= asciiDecodeLimit) { |
| 672 | let text = "" |
| 673 | let index = 0 |
| 674 | for (; index < size; index++) { |
| 675 | const code = bytes[offset + index] |
| 676 | if (code > 0x7f) break |
| 677 | text += String.fromCharCode(code) |
| 678 | } |
| 679 | if (index === size) return text |
| 680 | } |
| 681 | if (utf8Slice !== undefined) { |
| 682 | const text = utf8Slice.call(bytes, offset, offset + size) |
| 683 | if (text.indexOf("\ufffd") === -1) return text |
| 684 | } |
| 685 | try { |
| 686 | return textDecoder.decode(view(bytes.buffer, bytes.byteOffset + offset, size)) |
| 687 | } catch { |
| 688 | throw new ParseError({ message: "Invalid UTF-8 in message" }) |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | const sharedWriter = new Writer(8192) |
| 693 | |