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

Method WriteUtf8

csharp/src/Fory/StringSerializer.cs:134–151  ·  view source on GitHub ↗
(WriteContext context, string value)

Source from the content-addressed store, hash-verified

132 }
133
134 private static void WriteUtf8(WriteContext context, string value)
135 {
136 int maxByteLength = Encoding.UTF8.GetMaxByteCount(value.Length);
137 Span<byte> destination = context.Writer.GetSpan(MaxVarUInt36SmallBytes + maxByteLength);
138 Span<byte> payload = destination.Slice(MaxVarUInt36SmallBytes);
139 int written = Encoding.UTF8.GetBytes(value.AsSpan(), payload);
140
141 ulong header = ((ulong)written << 2) | (ulong)ForyStringEncoding.Utf8;
142 Span<byte> headerBuf = stackalloc byte[MaxVarUInt36SmallBytes];
143 int headerBytes = EncodeVarUInt36Small(headerBuf, header);
144 if (headerBytes != MaxVarUInt36SmallBytes)
145 {
146 payload.Slice(0, written).CopyTo(destination.Slice(headerBytes));
147 }
148
149 headerBuf.Slice(0, headerBytes).CopyTo(destination);
150 context.Writer.Advance(headerBytes + written);
151 }
152
153 private static void WriteUtf16(WriteContext context, string value)
154 {

Callers

nothing calls this directly

Calls 4

GetSpanMethod · 0.80
SliceMethod · 0.80
AdvanceMethod · 0.80
CopyToMethod · 0.45

Tested by

no test coverage detected