Beispiel #1
0
        /// <summary>
        /// Writes the raw bytes value as base 64 encoded JSON string as an element of a JSON array.
        /// </summary>
        /// <param name="bytes">The binary data to be written as a base 64 encoded JSON string element of a JSON array.</param>
        /// <remarks>
        /// The bytes are encoded before writing.
        /// </remarks>
        /// <exception cref="ArgumentException">
        /// Thrown when the specified value is too large.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// Thrown if this would result in an invalid JSON to be written (while validation is enabled).
        /// </exception>
        public void WriteBase64StringValue(ReadOnlySpan <byte> bytes)
        {
            JsonWriterHelper.ValidateBytes(bytes);

            WriteBase64ByOptions(bytes);

            SetFlagToAddListSeparatorBeforeNextItem();
            _tokenType = JsonTokenType.String;
        }
        private void WriteBase64StringHelper(ReadOnlySpan <byte> utf8PropertyName, ReadOnlySpan <byte> bytes)
        {
            Debug.Assert(utf8PropertyName.Length <= JsonConstants.MaxTokenSize);

            JsonWriterHelper.ValidateBytes(bytes);

            WriteBase64ByOptions(utf8PropertyName, bytes);

            SetFlagToAddListSeparatorBeforeNextItem();
            _tokenType = JsonTokenType.String;
        }
        /// <summary>
        /// Writes the pre-encoded property name and raw bytes value (as a Base64 encoded JSON string) as part of a name/value pair of a JSON object.
        /// </summary>
        /// <param name="propertyName">The JSON-encoded name of the property to write.</param>
        /// <param name="bytes">The binary data to write as Base64 encoded text.</param>
        /// <exception cref="InvalidOperationException">
        /// Thrown if this would result in invalid JSON being written (while validation is enabled).
        /// </exception>
        public void WriteBase64String(JsonEncodedText propertyName, ReadOnlySpan <byte> bytes)
        {
            ReadOnlySpan <byte> utf8PropertyName = propertyName.EncodedUtf8Bytes;

            Debug.Assert(utf8PropertyName.Length <= JsonConstants.MaxUnescapedTokenSize);

            JsonWriterHelper.ValidateBytes(bytes);

            WriteBase64ByOptions(utf8PropertyName, bytes);

            SetFlagToAddListSeparatorBeforeNextItem();
            _tokenType = JsonTokenType.String;
        }