MCPcopy Create free account
hub / github.com/Effect-TS/effect / decodeUtf8

Function decodeUtf8

packages/sql/pg/src/PgProtocol.ts:670–690  ·  view source on GitHub ↗
(bytes: Uint8Array, offset: number, size: number)

Source from the content-addressed store, hash-verified

668 ?.prototype?.utf8Slice
669
670const 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
692const sharedWriter = new Writer(8192)
693

Callers 1

cStringMethod · 0.70

Calls 3

viewFunction · 0.70
callMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected