MCPcopy Create free account
hub / github.com/apache/fory / readUTF16LE

Function readUTF16LE

go/fory/string.go:90–109  ·  view source on GitHub ↗
(buf *ByteBuffer, byteCount int, err *Error)

Source from the content-addressed store, hash-verified

88}
89
90func readUTF16LE(buf *ByteBuffer, byteCount int, err *Error) string {
91 if byteCount&1 != 0 {
92 err.SetError(InvalidUTF16StringError(byteCount))
93 return ""
94 }
95
96 data := buf.ReadBinary(byteCount, err)
97 if err.HasError() {
98 return ""
99 }
100
101 // Reconstruct UTF-16 code units
102 charCount := byteCount / 2
103 u16s := make([]uint16, charCount)
104 for i := 0; i < byteCount; i += 2 {
105 u16s[i/2] = uint16(data[i]) | uint16(data[i+1])<<8
106 }
107
108 return string(utf16.Decode(u16s))
109}
110
111func readUTF8(buf *ByteBuffer, size int, err *Error) string {
112 data := buf.ReadBinary(size, err)

Callers 6

readStringFunction · 0.85

Calls 7

InvalidUTF16StringErrorFunction · 0.85
uint16Function · 0.50
stringFunction · 0.50
SetErrorMethod · 0.45
ReadBinaryMethod · 0.45
HasErrorMethod · 0.45
DecodeMethod · 0.45