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

◆ Write() [5/21]

virtual void System.IO.BinaryWriter.Write ( char ch)
inlinevirtualinherited

Definition at line 156 of file BinaryWriter.cs.

157 {
158 if (!Rune.TryCreate(ch, out var result))
159 {
160 throw new ArgumentException(SR.Arg_SurrogatesNotAllowedAsSingleChar);
161 }
162 Span<byte> span = stackalloc byte[8];
163 if (_useFastUtf8)
164 {
165 int length = result.EncodeToUtf8(span);
166 OutStream.Write(span.Slice(0, length));
167 return;
168 }
169 byte[] array = null;
170 int maxByteCount = _encoding.GetMaxByteCount(1);
171 if (maxByteCount > span.Length)
172 {
173 array = ArrayPool<byte>.Shared.Rent(maxByteCount);
174 span = array;
175 }
176 int bytes = _encoding.GetBytes(MemoryMarshal.CreateReadOnlySpan(ref ch, 1), span);
177 OutStream.Write(span.Slice(0, bytes));
178 if (array != null)
179 {
181 }
182 }
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
readonly bool _useFastUtf8
readonly Encoding _encoding
void Write(byte[] buffer, int offset, int count)
virtual byte[] GetBytes(char[] chars)
Definition Encoding.cs:781
int GetMaxByteCount(int charCount)
static bool TryCreate(char ch, out Rune result)
Definition Rune.cs:511

References System.IO.BinaryWriter._encoding, System.IO.BinaryWriter._useFastUtf8, System.SR.Arg_SurrogatesNotAllowedAsSingleChar, System.array, System.bytes, System.ch, System.Text.Encoding.GetBytes(), System.Text.Encoding.GetMaxByteCount(), System.length, System.Span< T >.Length, System.IO.BinaryWriter.OutStream, System.Buffers.ArrayPool< T >.Shared, System.Span< T >.Slice(), System.Text.Rune.TryCreate(), and System.IO.Stream.Write().