/// <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)); }