Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
PooledByteBufferWriter.cs
Go to the documentation of this file.
2using System.IO;
5
6namespace System.Text.Json;
7
8internal sealed class PooledByteBufferWriter : IBufferWriter<byte>, IDisposable
9{
10 private byte[] _rentedBuffer;
11
12 private int _index;
13
15
16 public int Capacity => _rentedBuffer.Length;
17
23
24 public void Clear()
25 {
27 }
28
29 private void ClearHelper()
30 {
31 _rentedBuffer.AsSpan(0, _index).Clear();
32 _index = 0;
33 }
34
35 public void Dispose()
36 {
37 if (_rentedBuffer != null)
38 {
41 _rentedBuffer = null;
43 }
44 }
45
46 public void Advance(int count)
47 {
48 _index += count;
49 }
50
52 {
54 return _rentedBuffer.AsMemory(_index);
55 }
56
57 public Span<byte> GetSpan(int sizeHint = 0)
58 {
60 return _rentedBuffer.AsSpan(_index);
61 }
62
67
69 {
71 }
72
74 {
75 if (sizeHint == 0)
76 {
77 sizeHint = 256;
78 }
79 int num = _rentedBuffer.Length - _index;
80 if (sizeHint <= num)
81 {
82 return;
83 }
84 int num2 = _rentedBuffer.Length;
85 int num3 = Math.Max(sizeHint, num2);
86 int num4 = num2 + num3;
87 if ((uint)num4 > 2147483647u)
88 {
89 num4 = num2 + sizeHint;
90 if ((uint)num4 > 2147483647u)
91 {
93 }
94 }
99 span.Clear();
101 }
102}
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
static byte Max(byte val1, byte val2)
Definition Math.cs:738
ValueTask WriteToStreamAsync(Stream destination, CancellationToken cancellationToken)
static void ThrowOutOfMemoryException_BufferMaximumSizeExceeded(uint capacity)
unsafe ReadOnlySpan< T > Span
void CopyTo(Span< T > destination)
Definition Span.cs:224