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

Function readString

go/fory/string.go:52–73  ·  view source on GitHub ↗

readString reads a string from buffer using xlang encoding

(buf *ByteBuffer, err *Error)

Source from the content-addressed store, hash-verified

50
51// readString reads a string from buffer using xlang encoding
52func readString(buf *ByteBuffer, err *Error) string {
53 header := buf.ReadVaruint36Small(err)
54 size := header >> 2 // Extract byte count
55 encoding := header & 0b11 // Extract encoding type
56 if intSize == 32 && size > uint64(MaxInt) {
57 err.SetError(fmt.Errorf("string byte count %d exceeds supported int range", size))
58 return ""
59 }
60
61 switch encoding {
62 case encodingLatin1:
63 return readLatin1(buf, int(size), err)
64 case encodingUTF16LE:
65 // For UTF16LE, size is byte count, need to convert to char count
66 return readUTF16LE(buf, int(size), err)
67 case encodingUTF8:
68 return readUTF8(buf, int(size), err)
69 default:
70 err.SetError(fmt.Errorf("invalid string encoding: %d", encoding))
71 return ""
72 }
73}
74
75// Specific encoding read methods
76func readLatin1(buf *ByteBuffer, size int, err *Error) string {

Callers 12

ReadDataMethod · 0.85
ReadStringSliceFunction · 0.85
ReadDataMethod · 0.85
ReadDataMethod · 0.85
readFastMethod · 0.85
ReadStringMethod · 0.85
readMapStringStringFunction · 0.85
readMapStringInt64Function · 0.85
readMapStringInt32Function · 0.85
readMapStringIntFunction · 0.85
readMapStringFloat64Function · 0.85
readMapStringBoolFunction · 0.85

Calls 6

readLatin1Function · 0.85
readUTF16LEFunction · 0.85
readUTF8Function · 0.85
ReadVaruint36SmallMethod · 0.80
uint64Function · 0.50
SetErrorMethod · 0.45

Tested by

no test coverage detected