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

Method ReadString

csharp/src/Fory/StringSerializer.cs:59–74  ·  view source on GitHub ↗
(ReadContext context)

Source from the content-addressed store, hash-verified

57 }
58
59 public static string ReadString(ReadContext context)
60 {
61 ulong header = context.Reader.ReadVarUInt36Small();
62 ulong encoding = header & 0x03;
63 int byteLength = checked((int)(header >> 2));
64 ReadOnlySpan<byte> bytes = context.Reader.ReadSpan(byteLength);
65 return encoding switch
66 {
67 // C# intentionally preserves platform UTF-8 replacement behavior; Rust is the runtime
68 // that provides checked UTF-8 string reads by default.
69 (ulong)ForyStringEncoding.Utf8 => Encoding.UTF8.GetString(bytes),
70 (ulong)ForyStringEncoding.Latin1 => DecodeLatin1(bytes),
71 (ulong)ForyStringEncoding.Utf16 => DecodeUtf16(bytes),
72 _ => throw new EncodingException($"unsupported string encoding {encoding}"),
73 };
74 }
75
76 private static string DecodeLatin1(ReadOnlySpan<byte> bytes)
77 {

Callers 7

SkipPayloadMethod · 0.45
ReadScalarPayloadMethod · 0.45
ReadMethod · 0.45
WriteAndReadStringMethod · 0.45
WriteAndReadStringMethod · 0.45

Calls 2

ReadVarUInt36SmallMethod · 0.80
ReadSpanMethod · 0.80