| 151 | } |
| 152 | |
| 153 | private static void WriteUtf16(WriteContext context, string value) |
| 154 | { |
| 155 | int byteLength = checked(value.Length * 2); |
| 156 | ulong header = ((ulong)byteLength << 2) | (ulong)ForyStringEncoding.Utf16; |
| 157 | Span<byte> headerBuf = stackalloc byte[MaxVarUInt36SmallBytes]; |
| 158 | int headerBytes = EncodeVarUInt36Small(headerBuf, header); |
| 159 | Span<byte> destination = context.Writer.GetSpan(headerBytes + byteLength); |
| 160 | headerBuf.Slice(0, headerBytes).CopyTo(destination); |
| 161 | int written = Encoding.Unicode.GetBytes(value.AsSpan(), destination.Slice(headerBytes)); |
| 162 | context.Writer.Advance(headerBytes + written); |
| 163 | } |
| 164 | |
| 165 | private static int EncodeVarUInt36Small(Span<byte> destination, ulong value) |
| 166 | { |