Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ WriteCharsCommonWithoutLengthPrefix()

void System.IO.BinaryWriter.WriteCharsCommonWithoutLengthPrefix ( ReadOnlySpan< char > chars,
bool useThisWriteOverride )
inlineprivateinherited

Definition at line 342 of file BinaryWriter.cs.

343 {
344 byte[] array;
345 if (chars.Length <= 65536)
346 {
347 int maxByteCount = _encoding.GetMaxByteCount(chars.Length);
348 if (maxByteCount <= 65536)
349 {
350 array = ArrayPool<byte>.Shared.Rent(maxByteCount);
352 WriteToOutStream(array, 0, bytes, useThisWriteOverride);
354 return;
355 }
356 }
357 array = ArrayPool<byte>.Shared.Rent(65536);
358 Encoder encoder = _encoding.GetEncoder();
359 bool completed;
360 do
361 {
362 encoder.Convert(chars, array, flush: true, out var charsUsed, out var bytesUsed, out completed);
363 if (bytesUsed != 0)
364 {
365 WriteToOutStream(array, 0, bytesUsed, useThisWriteOverride);
366 }
367 chars = chars.Slice(charsUsed);
368 }
369 while (!completed);
371 void WriteToOutStream(byte[] buffer, int offset, int count, bool useThisWriteOverride)
372 {
373 if (useThisWriteOverride)
374 {
376 }
377 else
378 {
380 }
381 }
382 }
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
readonly Encoding _encoding
void Write(byte[] buffer, int offset, int count)
virtual void Convert(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex, int byteCount, bool flush, out int charsUsed, out int bytesUsed, out bool completed)
Definition Encoder.cs:135
virtual byte[] GetBytes(char[] chars)
Definition Encoding.cs:781
int GetMaxByteCount(int charCount)
virtual Encoder GetEncoder()
Definition Encoding.cs:1009

References System.IO.BinaryWriter._encoding, System.array, System.buffer, System.bytes, System.chars, System.Text.Encoder.Convert(), System.count, System.Text.Encoding.GetBytes(), System.Text.Encoding.GetEncoder(), System.Text.Encoding.GetMaxByteCount(), System.offset, System.IO.BinaryWriter.OutStream, System.Buffers.ArrayPool< T >.Shared, System.IO.Write, and System.IO.Stream.Write().

Referenced by System.IO.BinaryWriter.Write(), System.IO.BinaryWriter.Write(), System.IO.BinaryWriter.Write(), and System.IO.BinaryWriter.Write().