/// <summary> /// Parses the current JSON token value from the source and decodes the Base64 encoded JSON string as bytes. /// Returns <see langword="true"/> if the entire token value is encoded as valid Base64 text and can be successfully /// decoded to bytes. /// Returns <see langword="false"/> otherwise. /// </summary> /// <exception cref="InvalidOperationException"> /// Thrown if trying to get the value of a JSON token that is not a <see cref="JsonTokenType.String"/>. /// <seealso cref="TokenType" /> /// </exception> public bool TryGetBytesFromBase64(out byte[] value) { if (TokenType != JsonTokenType.String) { throw ThrowHelper.GetInvalidOperationException_ExpectedString(TokenType); } ReadOnlySpan <byte> span = HasValueSequence ? ValueSequence.ToArray() : ValueSpan; if (_stringHasEscaping) { int idx = span.IndexOf(JsonConstants.BackSlash); Debug.Assert(idx != -1); return(JsonReaderHelper.TryGetUnescapedBase64Bytes(span, idx, out value)); } Debug.Assert(span.IndexOf(JsonConstants.BackSlash) == -1); return(JsonReaderHelper.TryDecodeBase64(span, out value)); }
public bool TryGetUInt16(out ushort value) { if (TokenType != JsonTokenType.Number) { throw ThrowHelper.GetInvalidOperationException_ExpectedNumber(TokenType); } ReadOnlySpan <byte> span = HasValueSequence ? ValueSequence.ToArray() : ValueSpan; if (Utf8Parser.TryParse(span, out ushort tmp, out int bytesConsumed) && span.Length == bytesConsumed) { value = tmp; return(true); } value = 0; return(false); }
/// <summary> /// Parses the current JSON token value from the source as a <see cref="bool"/>. /// Returns <see langword="true"/> if the TokenType is JsonTokenType.True and <see langword="false"/> if the TokenType is JsonTokenType.False. /// </summary> /// <exception cref="InvalidOperationException"> /// Thrown if trying to get the value of a JSON token that is not a boolean (i.e. <see cref="JsonTokenType.True"/> or <see cref="JsonTokenType.False"/>). /// <seealso cref="TokenType" /> /// </exception> public bool GetBoolean() { ReadOnlySpan <byte> span = HasValueSequence ? ValueSequence.ToArray() : ValueSpan; if (TokenType == JsonTokenType.True) { Debug.Assert(span.Length == 4); return(true); } else if (TokenType == JsonTokenType.False) { Debug.Assert(span.Length == 5); return(false); } else { throw ThrowHelper.GetInvalidOperationException_ExpectedBoolean(TokenType); } }
/// <summary> /// Parses the current JSON token value from the source, unescaped, and transcoded as a <see cref="string"/>. /// </summary> /// <exception cref="InvalidOperationException"> /// Thrown if trying to get the value of the JSON token that is not a string /// (i.e. other than <see cref="JsonTokenType.String"/> or <see cref="JsonTokenType.PropertyName"/>). /// <seealso cref="TokenType" /> /// It will also throw when the JSON string contains invalid UTF-8 bytes, or invalid UTF-16 surrogates. /// </exception> public string GetString() { if (TokenType != JsonTokenType.String && TokenType != JsonTokenType.PropertyName) { throw ThrowHelper.GetInvalidOperationException_ExpectedString(TokenType); } ReadOnlySpan <byte> span = HasValueSequence ? ValueSequence.ToArray() : ValueSpan; if (_stringHasEscaping) { int idx = span.IndexOf(JsonConstants.BackSlash); Debug.Assert(idx != -1); return(JsonReaderHelper.GetUnescapedString(span, idx)); } Debug.Assert(span.IndexOf(JsonConstants.BackSlash) == -1); return(JsonReaderHelper.TranscodeHelper(span)); }
public TResult Invoke(ValueSequence <T, TSource, TSourceEnumerator> seq) { return(seq.Aggregate(Seed, Func, ResultSelector)); }
public T Invoke(ValueSequence <T, TSource, TSourceEnumerator> seq) { return(seq.Aggregate(Func)); }
public TAccumulate Invoke(ValueSequence <T, TSource, TSourceEnumerator> seq) { return(seq.Aggregate(Seed, Func)); }