Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ReadStack.cs
Go to the documentation of this file.
7
8namespace System.Text.Json;
9
10[DebuggerDisplay("Path:{JsonPath()} Current: ConverterStrategy.{Current.JsonTypeInfo.PropertyInfoForTypeInfo.ConverterStrategy}, {Current.JsonTypeInfo.Type.Name}")]
11internal struct ReadStack
12{
13 internal static readonly char[] SpecialCharacters = new char[18]
14 {
15 '.', ' ', '\'', '/', '"', '[', ']', '(', ')', '\t',
16 '\n', '\r', '\f', '\b', '\\', '\u0085', '\u2028', '\u2029'
17 };
18
20
22
23 private int _count;
24
25 private int _continuationCount;
26
28
29 public long BytesConsumed;
30
31 public bool ReadAhead;
32
34
36
37 public bool UseFastPath;
38
40
41 private void EnsurePushCapacity()
42 {
43 if (_stack == null)
44 {
45 _stack = new ReadStackFrame[4];
46 }
47 else if (_count - 1 == _stack.Length)
48 {
49 Array.Resize(ref _stack, 2 * _stack.Length);
50 }
51 }
52
58
73
113
114 public void Pop(bool success)
115 {
116 if (!success)
117 {
118 if (_continuationCount == 0)
119 {
120 if (_count == 1)
121 {
123 _count = 0;
124 return;
125 }
128 }
129 else if (--_count == 0)
130 {
131 return;
132 }
134 Current = _stack[_count - 1];
135 }
136 else if (--_count > 0)
137 {
138 Current = _stack[_count - 1];
139 }
141 }
142
143 public string JsonPath()
144 {
146 int num = Math.Max(_count, _continuationCount);
147 for (int i = 0; i < num - 1; i++)
148 {
150 }
151 if (_continuationCount == 0)
152 {
154 }
155 return stringBuilder.ToString();
156 static void AppendPropertyName(StringBuilder sb, string propertyName)
157 {
158 if (propertyName != null)
159 {
160 if (propertyName.IndexOfAny(SpecialCharacters) != -1)
161 {
162 sb.Append("['");
164 sb.Append("']");
165 }
166 else
167 {
168 sb.Append('.');
170 }
171 }
172 }
173 static void AppendStackFrame(StringBuilder sb, ref ReadStackFrame frame)
174 {
175 string propertyName2 = GetPropertyName(ref frame);
177 if (frame.JsonTypeInfo != null && frame.IsProcessingEnumerable() && frame.ReturnValue is IEnumerable enumerable2 && (frame.ObjectState == StackFrameObjectState.None || frame.ObjectState == StackFrameObjectState.CreatedObject || frame.ObjectState == StackFrameObjectState.ReadElements))
178 {
179 sb.Append('[');
180 sb.Append(GetCount(enumerable2));
181 sb.Append(']');
182 }
183 }
184 static int GetCount(IEnumerable enumerable)
185 {
186 if (enumerable is ICollection collection)
187 {
188 return collection.Count;
189 }
190 int num2 = 0;
191 IEnumerator enumerator = enumerable.GetEnumerator();
192 while (enumerator.MoveNext())
193 {
194 num2++;
195 }
196 return num2;
197 }
198 static string GetPropertyName(ref ReadStackFrame frame)
199 {
200 string result = null;
201 byte[] array = frame.JsonPropertyName;
202 if (array == null)
203 {
204 if (frame.JsonPropertyNameAsString != null)
205 {
206 result = frame.JsonPropertyNameAsString;
207 }
208 else
209 {
210 array = frame.JsonPropertyInfo?.NameAsUtf8Bytes ?? frame.CtorArgumentState?.JsonParameterInfo?.NameAsUtf8Bytes;
211 }
212 }
213 if (array != null)
214 {
216 }
217 return result;
218 }
219 }
220
221 [MethodImpl(MethodImplOptions.AggressiveInlining)]
248}
void Add(TKey key, TValue value)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
JsonParameterInfo JsonParameterInfo
static string Utf8GetString(ReadOnlySpan< byte > bytes)
StringBuilder Append(char value, int repeatCount)
JsonNumberHandling? NumberHandling
static readonly char[] SpecialCharacters
Definition ReadStack.cs:13
void Pop(bool success)
Definition ReadStack.cs:114
ReadStackFrame Current
Definition ReadStack.cs:19
void Initialize(JsonTypeInfo jsonTypeInfo, bool supportContinuation=false)
Definition ReadStack.cs:59
ReferenceResolver ReferenceResolver
Definition ReadStack.cs:33
void Initialize(Type type, JsonSerializerOptions options, bool supportContinuation)
Definition ReadStack.cs:53
ReadStackFrame[] _stack
Definition ReadStack.cs:21
List< ArgumentState > _ctorArgStateCache
Definition ReadStack.cs:27