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

◆ TryParseValue() [1/2]

static bool System.Text.Json.JsonDocument.TryParseValue ( ref Utf8JsonReader reader,
[NotNullWhen(true)] out JsonDocument document,
bool shouldThrow,
bool useArrayPools )
inlinestaticpackage

Definition at line 1236 of file JsonDocument.cs.

1237 {
1238 JsonReaderState currentState = reader.CurrentState;
1239 CheckSupportedOptions(currentState.Options, "reader");
1240 Utf8JsonReader utf8JsonReader = reader;
1241 ReadOnlySpan<byte> readOnlySpan = default(ReadOnlySpan<byte>);
1243 try
1244 {
1245 JsonTokenType tokenType = reader.TokenType;
1246 ReadOnlySpan<byte> bytes;
1247 if ((tokenType == JsonTokenType.None || tokenType == JsonTokenType.PropertyName) && !reader.Read())
1248 {
1249 if (shouldThrow)
1250 {
1251 bytes = default(ReadOnlySpan<byte>);
1252 ThrowHelper.ThrowJsonReaderException(ref reader, ExceptionResource.ExpectedJsonTokens, 0, bytes);
1253 }
1254 reader = utf8JsonReader;
1255 document = null;
1256 return false;
1257 }
1258 switch (reader.TokenType)
1259 {
1260 case JsonTokenType.StartObject:
1261 case JsonTokenType.StartArray:
1262 {
1263 long tokenStartIndex = reader.TokenStartIndex;
1264 if (!reader.TrySkip())
1265 {
1266 if (shouldThrow)
1267 {
1268 bytes = default(ReadOnlySpan<byte>);
1269 ThrowHelper.ThrowJsonReaderException(ref reader, ExceptionResource.ExpectedJsonTokens, 0, bytes);
1270 }
1271 reader = utf8JsonReader;
1272 document = null;
1273 return false;
1274 }
1276 ReadOnlySequence<byte> originalSequence2 = reader.OriginalSequence;
1277 if (originalSequence2.IsEmpty)
1278 {
1279 bytes = reader.OriginalSpan;
1280 readOnlySpan = checked(bytes.Slice((int)tokenStartIndex, (int)num3));
1281 }
1282 else
1283 {
1285 }
1286 break;
1287 }
1288 case JsonTokenType.True:
1289 case JsonTokenType.False:
1290 case JsonTokenType.Null:
1291 if (useArrayPools)
1292 {
1293 if (reader.HasValueSequence)
1294 {
1295 sequence = reader.ValueSequence;
1296 }
1297 else
1298 {
1299 readOnlySpan = reader.ValueSpan;
1300 }
1301 break;
1302 }
1303 document = CreateForLiteral(reader.TokenType);
1304 return true;
1305 case JsonTokenType.Number:
1306 if (reader.HasValueSequence)
1307 {
1308 sequence = reader.ValueSequence;
1309 }
1310 else
1311 {
1312 readOnlySpan = reader.ValueSpan;
1313 }
1314 break;
1315 case JsonTokenType.String:
1316 {
1317 ReadOnlySequence<byte> originalSequence = reader.OriginalSequence;
1318 if (originalSequence.IsEmpty)
1319 {
1320 bytes = reader.ValueSpan;
1321 int length = bytes.Length + 2;
1322 readOnlySpan = reader.OriginalSpan.Slice((int)reader.TokenStartIndex, length);
1323 break;
1324 }
1325 long num = 2L;
1326 if (reader.HasValueSequence)
1327 {
1328 num += reader.ValueSequence.Length;
1329 }
1330 else
1331 {
1332 long num2 = num;
1333 bytes = reader.ValueSpan;
1334 num = num2 + bytes.Length;
1335 }
1336 sequence = originalSequence.Slice(reader.TokenStartIndex, num);
1337 break;
1338 }
1339 default:
1340 if (shouldThrow)
1341 {
1342 bytes = reader.ValueSpan;
1343 byte nextByte = bytes[0];
1344 bytes = default(ReadOnlySpan<byte>);
1345 ThrowHelper.ThrowJsonReaderException(ref reader, ExceptionResource.ExpectedStartOfValueNotFound, nextByte, bytes);
1346 }
1347 reader = utf8JsonReader;
1348 document = null;
1349 return false;
1350 }
1351 }
1352 catch
1353 {
1354 reader = utf8JsonReader;
1355 throw;
1356 }
1358 if (useArrayPools)
1359 {
1360 byte[] array = ArrayPool<byte>.Shared.Rent(num4);
1361 Span<byte> destination = array.AsSpan(0, num4);
1362 try
1363 {
1364 if (readOnlySpan.IsEmpty)
1365 {
1366 sequence.CopyTo(destination);
1367 }
1368 else
1369 {
1370 readOnlySpan.CopyTo(destination);
1371 }
1372 document = Parse(array.AsMemory(0, num4), currentState.Options, array);
1373 }
1374 catch
1375 {
1376 destination.Clear();
1378 throw;
1379 }
1380 }
1381 else
1382 {
1383 byte[] array2 = ((!readOnlySpan.IsEmpty) ? readOnlySpan.ToArray() : BuffersExtensions.ToArray(in sequence));
1384 document = ParseUnrented(array2, currentState.Options, reader.TokenType);
1385 }
1386 return true;
1387 }
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
static JsonDocument CreateForLiteral(JsonTokenType tokenType)
static void CheckSupportedOptions(JsonReaderOptions readerOptions, string paramName)
static JsonDocument ParseUnrented(ReadOnlyMemory< byte > utf8Json, JsonReaderOptions readerOptions, JsonTokenType tokenType=JsonTokenType.None)
static void Parse(ReadOnlySpan< byte > utf8JsonSpan, JsonReaderOptions readerOptions, ref MetadataDb database, ref StackRowStack stack)
ReadOnlySequence< T > Slice(long start, long length)

References System.array, System.bytes, System.Text.Json.JsonDocument.CheckSupportedOptions(), System.Span< T >.CopyTo(), System.Text.Json.JsonDocument.CreateForLiteral(), System.destination, System.Text.Json.Dictionary, System.L, System.length, System.Text.Json.JsonDocument.Parse(), System.Text.Json.JsonDocument.ParseUnrented(), System.Buffers.ArrayPool< T >.Shared, System.Buffers.ReadOnlySequence< T >.Slice(), and System.Text.Json.ThrowHelper.ThrowJsonReaderException().