Beispiel #1
0
        private IImageSwizzle CreateSwizzle(Size size, IEncodingInfo encoding)
        {
            switch (SelectedSwizzleExtension.Name)
            {
            case "NDS":
                return(new NitroSwizzle(size.Width, size.Height));

            case "3DS":
                return(new CTRSwizzle(size.Width, size.Height, CtrTransformation.None, true));

            case "WiiU":
                var swizzleTileMode = SelectedSwizzleExtension.GetParameterValue <byte>("SwizzleTileMode");
                return(new CafeSwizzle(swizzleTileMode, encoding.BitsPerValue > 32, encoding.BitDepth, size.Width, size.Height));

            case "Custom":
                var swizzleText        = SelectedSwizzleExtension.GetParameterValue <string>("BitMapping");
                var escapedSwizzleText = swizzleText.Replace(" ", "");

                var pointStrings = escapedSwizzleText.Substring(1, escapedSwizzleText.Length - 2)
                                   .Split(new[] { "},{" }, StringSplitOptions.None);
                var finalPoints = pointStrings.Select(x => x.Split(','))
                                  .Select(x => (int.Parse(x[0]), int.Parse(x[1])));

                var masterSwizzle = new MasterSwizzle(size.Width, Point.Empty, finalPoints.ToArray());
                return(new CustomSwizzle(size.Width, size.Height, masterSwizzle));

            default:
                return(null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes new instance of <see cref="SASLChallengeArguments"/> with given parameters.
        /// </summary>
        /// <param name="readArray">The array where to read the response sent by remote. May be <c>null</c> if no response was received yet.</param>
        /// <param name="readOffset">The offset in <paramref name="readArray"/> where the remote response starts.</param>
        /// <param name="readCount">The amount of bytes in <paramref name="readArray"/> reserved by remote response.</param>
        /// <param name="writeArray">The <see cref="ResizableArray{T}"/> where to write the response by the challenge. May not be <c>null</c>.</param>
        /// <param name="writeOffset">The offset in <paramref name="writeArray"/> where to start writing response by this challenge.</param>
        /// <param name="encoding">The <see cref="IEncodingInfo"/> used by the protocol. May be <c>null</c> if protocol is not textual.</param>
        /// <param name="credentials">The protocol specific credentials object. May be <c>null</c>.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="writeArray"/> is <c>null</c>.</exception>
        public SASLChallengeArguments(
            Byte[] readArray,
            Int32 readOffset,
            Int32 readCount,
            ResizableArray <Byte> writeArray,
            Int32 writeOffset,
            IEncodingInfo encoding,
            Object credentials
            )
        {
            if (readArray == null)
            {
                this.ReadArray  = Empty <Byte> .Array;
                this.ReadOffset = this.ReadCount = -1;
            }
            else
            {
                this.ReadArray  = readArray;
                this.ReadOffset = readOffset;
                this.ReadCount  = readCount;
            }

            this.WriteArray  = ArgumentValidator.ValidateNotNull(nameof(writeArray), writeArray);
            this.WriteOffset = writeOffset;
            this.Encoding    = encoding;
            this.Credentials = credentials;
        }
 /// <summary>
 /// Creates new instance of <see cref="StreamCharacterReaderLogic"/> with given <see cref="IEncodingInfo"/>.
 /// </summary>
 /// <param name="encodingInfo">The <see cref="IEncodingInfo"/>.</param>
 /// <exception cref="ArgumentNullException">If <paramref name="encodingInfo"/> is <c>null</c>.</exception>
 public StreamCharacterReaderLogic(
     IEncodingInfo encodingInfo
     )
 {
     this.Encoding = ArgumentValidator.ValidateNotNull(nameof(encodingInfo), encodingInfo);
     this._minChar = encodingInfo.MinCharByteCount;
     this._chars   = new Char[2];
 }
        /// <summary>
        /// This method will read the string written by <see cref="WriteString"/> method, assuming it will end in some ASCII character is never present in the string.
        /// </summary>
        /// <param name="encodingInfo">The <see cref="IEncodingInfo"/> to use.</param>
        /// <param name="array">The byte array to read from.</param>
        /// <param name="offset">The offset in <paramref name="array"/> where to start reading.</param>
        /// <param name="count">The maximum amount of bytes to read.</param>
        /// <param name="firstExclusiveASCIICharacter">The ASCII character which marks the end of the string. If it is not found, then the end of the string will be <paramref name="offset"/> + <paramref name="count"/>.</param>
        /// <param name="denormalizer">The optional denormalizer callback.</param>
        /// <returns>Deserialized string.</returns>
        public static String ReadString(
            IEncodingInfo encodingInfo,
            Byte[] array,
            ref Int32 offset,
            Int32 count,
            Byte firstExclusiveASCIICharacter,
            CustomStringDenormalizer denormalizer = null
            )
        {
            var    endIdx = encodingInfo.IndexOfASCIICharacterOrMax(array, offset, count, firstExclusiveASCIICharacter);
            String retVal;

            count = endIdx - offset;
            if (denormalizer == null)
            {
                // Can just create string
                retVal = encodingInfo.Encoding.GetString(array, offset, count);
            }
            else
            {
                StringBuilder sb       = null;
                var           encoding = encodingInfo.Encoding;
                var           prev     = offset;
                var           min      = encodingInfo.MinCharByteCount;
                for (var i = offset; i < endIdx; i += min)
                {
                    var replacement = denormalizer(encodingInfo, array, i);
                    if (replacement != null)
                    {
                        if (sb == null)
                        {
                            sb = new StringBuilder();
                        }
                        // Append previous chunk
                        sb.Append(encoding.GetString(array, prev, i - prev));
                        sb.Append(replacement);
                    }
                }


                if (sb == null)
                {
                    // No escapable strings
                    retVal = encoding.GetString(array, offset, count);
                }
                else
                {
                    // Append final chunk
                    sb.Append(encoding.GetString(array, prev, endIdx - prev));
                    retVal = sb.ToString();
                }
            }
            offset += count;

            return(retVal);
        }
Beispiel #5
0
 /// <summary>
 /// Creates new instance of <see cref="StreamCharacterWriterLogic"/> with given parameters.
 /// </summary>
 /// <param name="encoding">The <see cref="IEncodingInfo"/> that will be used to encode characters.</param>
 /// <param name="maxBufferSize">The maximum allowed buffer size that any <see cref="StreamWriterWithResizableBuffer"/> will be allowed to have.</param>
 public StreamCharacterWriterLogic(
     IEncodingInfo encoding,
     Int32 maxBufferSize
     )
 {
     this._encoding          = ArgumentValidator.ValidateNotNull(nameof(encoding), encoding);
     this._maxSingleCharSize = encoding.MaxCharByteCount;
     this._auxArray          = new Char[2];
     this._maxBufferSize     = Math.Max(maxBufferSize, this._maxSingleCharSize);
 }
Beispiel #6
0
 /// <summary>
 /// Asynchronously writes JSON value (array, object, or primitive value) to this <see cref="StreamWriterWithResizableBuffer"/> using given <see cref="IEncodingInfo"/>.
 /// Tries to keep the buffer of this stream as little as possible, and allocating as little as possible any other extra objects than created JSON objects (currently parsing a <see cref="Double"/> needs to allocate string).
 /// </summary>
 /// <param name="stream">This <see cref="StreamWriterWithResizableBuffer"/>.</param>
 /// <param name="encoding">The <see cref="IEncodingInfo"/> to use.</param>
 /// <param name="jsonValue">The JSON value.</param>
 /// <returns>A task which when completed will contain the amount of bytes written to this stream.</returns>
 /// <exception cref="NullReferenceException">If this <see cref="StreamWriterWithResizableBuffer"/> is <c>null</c>.</exception>
 /// <exception cref="ArgumentNullException">If <paramref name="encoding"/> is <c>null</c>; or if <paramref name="jsonValue"/> or any of the JSON values it contains is <c>null</c>.</exception>
 /// <exception cref="NotSupportedException">When a <see cref="JToken"/> is encountered which is not <see cref="JArray"/>, <see cref="JObject"/> or <see cref="JValue"/>; or when the value of <see cref="JValue"/> is not recognized.</exception>
 public static ValueTask <Int32> WriteJSONTTokenAsync(
     this StreamWriterWithResizableBuffer stream,
     IEncodingInfo encoding,
     JToken jsonValue
     )
 {
     return(PerformWriteJSONTTokenAsync(
                ArgumentValidator.ValidateNotNullReference(stream),
                ArgumentValidator.ValidateNotNull(nameof(encoding), encoding),
                jsonValue
                ));
 }
Beispiel #7
0
    private static void TransformToEscape(
        IEncodingInfo encoding,
        Byte[] array,
        ref Int32 idx,
        Char charRead
        )
    {
        Byte replacementByte = 0;

        switch (charRead)
        {
        case STR_END:
        case STR_ESCAPE_PREFIX:
        case '/':
            // Actual value is just just read char minus the '\'
            replacementByte = (Byte)charRead;
            break;

        case '\b':
            // Backspace
            replacementByte = (Byte)'b';
            break;

        case '\f':
            // Form feed
            replacementByte = (Byte)'f';
            break;

        case '\n':
            // New line
            replacementByte = (Byte)'n';
            break;

        case '\r':
            // Carriage return
            replacementByte = (Byte)'r';
            break;

        case '\t':
            // Horizontal tab
            replacementByte = (Byte)'t';
            break;

        // \u escape is not needed - it is provided mainly for humans.
        default:
            throw new NotSupportedException($"Unsupported escape sequence: '{charRead}'.");
        }

        if (replacementByte != 0)
        {
            encoding.WriteASCIIByte(array, ref idx, replacementByte);
        }
    }
Beispiel #8
0
    private static Int32 WriteJSONString(
        StreamWriterWithResizableBuffer stream,
        IEncodingInfo encoding,
        String str
        )
    {
        // Write starting quote
        var asciiSize = encoding.BytesPerASCIICharacter;
        var eencoding = encoding.Encoding;
        // Allocate enough bytes for whole string and 2 quotes, we will allocate more as we encounter escapable characters
        var range = stream.ReserveBufferSegment(eencoding.GetByteCount(str) + 2 * asciiSize);
        var array = stream.Buffer;
        var start = range.Offset;
        var idx   = start;

        encoding.WriteASCIIByte(array, ref idx, (Byte)STR_START);

        // Write contents in chunks
        var prevStrIdx = 0;

        for (var i = 0; i < str.Length; ++i)
        {
            var c = str[i];
            if (NeedsEscaping(c))
            {
                // Append previous chunk
                idx += eencoding.GetBytes(str, prevStrIdx, i - prevStrIdx, array, idx);
                // Make sure we have room for escape character
                stream.ReserveBufferSegment(asciiSize);
                array = stream.Buffer;
                // Append escape character
                encoding.WriteASCIIByte(array, ref idx, (Byte)STR_ESCAPE_PREFIX);
                // Append escape sequence latter character
                TransformToEscape(encoding, array, ref idx, c);
                // Update index
                prevStrIdx = i + 1;
            }
        }

        // Append final chunk
        var finalChunkSize = str.Length - prevStrIdx;

        if (finalChunkSize > 0)
        {
            idx += eencoding.GetBytes(str, prevStrIdx, finalChunkSize, array, idx);
        }

        // Append closing quote
        encoding.WriteASCIIByte(array, ref idx, (Byte)STR_END);

        return(idx - start);
    }
Beispiel #9
0
    private static Int32 CalculateJSONStringValueSize(String str, IEncodingInfo encoding)
    {
        // '"' followed by string followed by '"', with '"', '\', '/', and control characters escaped
        var asciiSize = encoding.BytesPerASCIICharacter;
        var retVal    = 2 * asciiSize + encoding.Encoding.GetByteCount(str);

        for (var i = 0; i < str.Length; ++i)
        {
            if (NeedsEscaping(str[i]))
            {
                retVal += asciiSize;
            }
        }

        return(retVal);
    }
        /// <summary>
        /// This method will write SASL string to given byte array using given <see cref="IEncodingInfo"/>, while escaping and transforming string as needed.
        /// See <see cref="CheckString"/> for more information about escaping and transforming.
        /// </summary>
        /// <param name="str">The string to write.</param>
        /// <param name="encodingInfo">The <see cref="IEncodingInfo"/> to use.</param>
        /// <param name="array">The byte array where to write the string.</param>
        /// <param name="offset">The offset in <paramref name="array"/> where to start writing.</param>
        /// <param name="normalizer">The optional custom normalizer callback to use.</param>
        /// <param name="checkResult">The result of <see cref="CheckString"/>, if it was used before calling this method.</param>
        /// <seealso cref="CheckString"/>
        /// <remarks>
        /// This method will not allocate any strings.
        /// </remarks>
        public static void WriteString(
            String str,
            IEncodingInfo encodingInfo,
            ResizableArray <Byte> array,
            ref Int32 offset,
            CustomStringNormalizer normalizer = null,
            Int32?checkResult = null
            )
        {
            var checkResultValue = checkResult ?? CheckString(str, normalizer);
            var encoding         = encodingInfo.Encoding;

            if (checkResultValue == -1)
            {
                // String may be written as-is
                array.CurrentMaxCapacity = offset + encoding.GetByteCount(str);
                encodingInfo.WriteString(array.Array, ref offset, str);
            }
            else
            {
                var maxCharByteCountDiff = encodingInfo.MaxCharByteCount - 1;

                String tmpStr;

                // Calculate byte size (actually, we are calculating the upper bound for byte size, but that's ok)
                var byteSize = encoding.GetByteCount(str);
                for (var i = checkResultValue; i < str.Length; ++i)
                {
                    var c = str[i];
                    if (c >= MIN_SPECIAL_CHAR)
                    {
                        // It is possible that we need to replace character
                        if (IsNonAsciiSpace(c))
                        {
                            // Mapping special space into "normal" space (0x20)
                            // Byte size doesn't grow at least.
                        }
                        else if (IsCommonlyMappedToNothing(c))
                        {
                            --byteSize;
                        }
                        else if ((tmpStr = normalizer?.Invoke(str, i)) != null)
                        {
                            byteSize += encoding.GetByteCount(tmpStr) - 1;
                        }
                    }
                }

                // Now we know that the string will take max 'byteSize' amount of bytes
                array.CurrentMaxCapacity = offset + byteSize;
                // We can get the actual array now, since we won't be resizing the ResizableArray anymore
                var buffer = array.Array;

                // Helper method to write chunks of "normal" characters
                var prev = 0;
                void WritePreviousChunk(Int32 charIdx, ref Int32 writeIdx)
                {
                    writeIdx += encoding.GetBytes(str, prev, charIdx - prev, buffer, writeIdx);
                    prev      = charIdx + 1;
                }

                for (var i = checkResultValue; i < str.Length; ++i)
                {
                    var c = str[i];
                    if (c >= MIN_SPECIAL_CHAR)
                    {
                        // It is possible that we need to replace character
                        if (IsNonAsciiSpace(c))
                        {
                            // Mapping special space into "normal" space (0x20)
                            WritePreviousChunk(i, ref offset);
                            encodingInfo.WriteASCIIByte(buffer, ref offset, 0x20);
                        }
                        else if (IsCommonlyMappedToNothing(c))
                        {
                            // Nothing additional to write
                            WritePreviousChunk(i, ref offset);
                        }
                        else if ((tmpStr = normalizer?.Invoke(str, i)) != null)
                        {
                            WritePreviousChunk(i, ref offset);
                            if (tmpStr.Length > 0)
                            {
                                encodingInfo.WriteString(buffer, ref offset, tmpStr);
                            }
                        }
                    }
                }

                if (prev < str.Length)
                {
                    // Write final chunk
                    WritePreviousChunk(str.Length - 1, ref offset);
                }
            }
        }
 /// <summary>
 /// Creates a new instance of <see cref="SwizzlePreparationContext"/>.
 /// </summary>
 /// <param name="encodingInfo">The meta information for the current encoding.</param>
 /// <param name="size">The exact or padded size of the image.</param>
 public SwizzlePreparationContext(IEncodingInfo encodingInfo, Size size)
 {
     EncodingInfo = encodingInfo;
     Size         = size;
 }
Beispiel #12
0
 /// <summary>
 /// Parses ASCII integer string to 32-bit integer from encoded string without allocating a string.
 /// Negative numbers are supported, as is optional <c>+</c> prefix.
 /// </summary>
 /// <param name="encoding">This <see cref="IEncodingInfo"/>.</param>
 /// <param name="array">The byte array containing encoded string.</param>
 /// <param name="offset">The offset in <paramref name="array"/> where to start reading from.</param>
 /// <param name="charCount">The optional character count. If this parameter is specified, then this method will only read specified maximum amount of characters. Furthermore, it may be specified that number takes *exactly* the given amount of characters.</param>
 /// <returns>The parsed integer.</returns>
 /// <exception cref="NullReferenceException">If this <see cref="IEncodingInfo"/> is <c>null</c>.</exception>
 /// <exception cref="ArgumentNullException">If <paramref name="array"/> is <c>null</c>.</exception>
 /// <exception cref="ArgumentException">If <paramref name="charCount"/> is specified, but the count was invalid.</exception>
 /// <exception cref="FormatException">If number string was malformed, or <paramref name="charCount"/> was specified with its exact match as <c>true</c> and the amount of characters read was less than specified.</exception>
 public static Int32 ParseInt32Textual(
     this IEncodingInfo encoding,
     Byte[] array,
     ref Int32 offset,
     (Int32 CharCount, Boolean CharCountExactMatch)?charCount = null
Beispiel #13
0
 private IImageSwizzle GetPixelRemapper(IEncodingInfo encodingInfo, Size paddedSize)
 {
     return(_remapPixels?.Invoke(new SwizzlePreparationContext(encodingInfo, paddedSize)));
 }
Beispiel #14
0
    private static async ValueTask <Int32> PerformWriteJSONTTokenAsync(
        StreamWriterWithResizableBuffer stream,
        IEncodingInfo encoding,
        JToken jsonValue
        )
    {
        ArgumentValidator.ValidateNotNull(nameof(jsonValue), jsonValue);
        Int32 bytesWritten;
        var   asciiSize = encoding.BytesPerASCIICharacter;
        Int32 max;

        (Int32 Offset, Int32 Count)range;
        switch (jsonValue)
        {
        case JArray array:
            range = stream.ReserveBufferSegment(asciiSize);
            encoding.WriteASCIIByte(stream.Buffer, ref range.Offset, (Byte)ARRAY_START);
            bytesWritten = range.Count;
            max          = array.Count;
            if (max > 0)
            {
                for (var i = 0; i < max; ++i)
                {
                    bytesWritten += await PerformWriteJSONTTokenAsync(stream, encoding, array[i]);

                    if (i < max - 1)
                    {
                        range = stream.ReserveBufferSegment(asciiSize);
                        encoding.WriteASCIIByte(stream.Buffer, ref range.Offset, (Byte)ARRAY_VALUE_DELIM);
                        bytesWritten += range.Count;
                    }
                }
            }
            range = stream.ReserveBufferSegment(asciiSize);
            encoding.WriteASCIIByte(stream.Buffer, ref range.Offset, (Byte)ARRAY_END);
            bytesWritten += await stream.FlushAsync();

            break;

        case JObject obj:
            range = stream.ReserveBufferSegment(asciiSize);
            encoding.WriteASCIIByte(stream.Buffer, ref range.Offset, (Byte)OBJ_START);
            bytesWritten = range.Count;
            max          = obj.Count;
            if (max > 0)
            {
                var j = 0;
                foreach (var kvp in obj)
                {
                    bytesWritten += WriteJSONString(stream, encoding, kvp.Key);
                    range         = stream.ReserveBufferSegment(asciiSize);
                    encoding.WriteASCIIByte(stream.Buffer, ref range.Offset, (Byte)OBJ_KEY_VALUE_DELIM);
                    bytesWritten += range.Count;
                    await stream.FlushAsync();

                    bytesWritten += await PerformWriteJSONTTokenAsync(stream, encoding, kvp.Value);

                    if (++j < max)
                    {
                        range = stream.ReserveBufferSegment(asciiSize);
                        encoding.WriteASCIIByte(stream.Buffer, ref range.Offset, (Byte)OBJ_VALUE_DELIM);
                        bytesWritten += range.Count;
                    }
                }
            }
            range = stream.ReserveBufferSegment(asciiSize);
            encoding.WriteASCIIByte(stream.Buffer, ref range.Offset, (Byte)OBJ_END);
            bytesWritten += await stream.FlushAsync();

            break;

        case JValue value:
            var val = value.Value;
            switch (val)
            {
            case String str:
                bytesWritten = WriteJSONString(stream, encoding, str);
                break;

            case Boolean boolean:
                // Write 'true' or 'false'
                range = stream.ReserveBufferSegment(boolean ? 4 : 5);
                encoding.WriteString(stream.Buffer, ref range.Offset, boolean ? "true" : "false");
                bytesWritten = range.Count;
                break;

            case Int64 i64:
                range = stream.ReserveBufferSegment(encoding.GetTextualIntegerRepresentationSize(i64));
                encoding.WriteIntegerTextual(stream.Buffer, ref range.Offset, i64);
                bytesWritten = range.Count;
                break;

            case Double dbl:
                // Have to allocate string :/
                var dblStr = dbl.ToString(System.Globalization.CultureInfo.InvariantCulture);
                range = stream.ReserveBufferSegment(encoding.Encoding.GetByteCount(dblStr));
                encoding.WriteString(stream.Buffer, ref range.Offset, dblStr);
                bytesWritten = range.Count;
                break;

            case null:
                // Write 'null'
                range = stream.ReserveBufferSegment(asciiSize * 4);
                encoding.WriteString(stream.Buffer, ref range.Offset, "null");
                bytesWritten = range.Count;
                break;

            default:
                throw new NotSupportedException($"Unsupported primitive value {val}.");
            }
            // Remember to flush stream
            await stream.FlushAsync();

            break;

        default:
            throw new NotSupportedException($"Unrecognized JToken type: {jsonValue?.GetType()}.");
        }

        return(bytesWritten);
    }
Beispiel #15
0
    private static Int32 PerformCalculateJTokenTextSize(IEncodingInfo encoding, JToken jsonValue)
    {
        ArgumentValidator.ValidateNotNull(nameof(jsonValue), jsonValue);

        var   asciiSize = encoding.BytesPerASCIICharacter;
        Int32 retVal;

        switch (jsonValue)
        {
        case JArray array:
            // '['followed by items with ',' in between them followed by ']'
            retVal = (2 + Math.Max(array.Count - 1, 0)) * asciiSize + array.Aggregate(0, (cur, curToken) => cur + PerformCalculateJTokenTextSize(encoding, curToken));
            break;

        case JObject obj:
            // '{' followed by items with ',' in between them followed by '}'
            // Each item has ':' between key and value
            retVal = (2 + Math.Max(obj.Count - 1, 0)) * asciiSize + Enumerable.Aggregate <KeyValuePair <String, JToken>, Int32>(obj, 0, (cur, curKvp) => cur + asciiSize + CalculateJSONStringValueSize(curKvp.Key, encoding) + PerformCalculateJTokenTextSize(encoding, curKvp.Value));
            break;

        case JValue simple:
            var val = simple.Value;
            switch (val)
            {
            case String str:
                retVal = CalculateJSONStringValueSize(str, encoding);
                break;

            case Boolean bol:
                retVal = (bol ? 4 : 5) * asciiSize;
                break;

            case Byte b:
            case SByte sb:
            case Int16 i16:
            case UInt16 u16:
            case Int32 i32:
            case UInt32 u32:
            case Int64 i64:
                retVal = encoding.GetTextualIntegerRepresentationSize((Int64)Convert.ChangeType(val, typeof(Int64)));
                break;

            // TODO UInt64
            case Single s:
            case Double d:
            case Decimal dec:
                retVal = encoding.Encoding.GetByteCount(((IFormattable)val).ToString(null, System.Globalization.CultureInfo.InvariantCulture.NumberFormat));
                break;

            case null:
                // Word 'null' has 4 ascii characters
                retVal = 4 * asciiSize;
                break;

            default:
                throw new NotSupportedException($"Unsupported primitive value {val}.");
            }
            break;

        default:
            throw new NotSupportedException($"Unrecognized JToken type: {jsonValue?.GetType()}.");
        }

        return(retVal);
    }
Beispiel #16
0
 /// <summary>
 /// Helper method to calculate how many bytes the given <see cref="JToken"/> will take using this encoding.
 /// </summary>
 /// <param name="encoding">This <see cref="IEncodingInfo"/>.</param>
 /// <param name="jsonValue">The <see cref="JToken"/>.</param>
 /// <returns>The amount of bytes the given <see cref="JToken"/> will take using this <see cref="IEncodingInfo"/>.</returns>
 /// <exception cref="NullReferenceException">If this <see cref="IEncodingInfo"/> is <c>null</c>.</exception>
 /// <exception cref="ArgumentNullException">If given <paramref name="jsonValue"/>, or any of the other <see cref="JToken"/>s it contains, is <c>null</c>.</exception>
 /// <exception cref="NotSupportedException">When a <see cref="JToken"/> is encountered which is not <see cref="JArray"/>, <see cref="JObject"/> or <see cref="JValue"/>; or when the value of <see cref="JValue"/> is not recognized.</exception>
 public static Int32 CalculateJTokenTextSize(this IEncodingInfo encoding, JToken jsonValue)
 {
     return(PerformCalculateJTokenTextSize(ArgumentValidator.ValidateNotNullReference(encoding), jsonValue));
 }