/// <summary>
        /// Writes a json node to the internal buffer.
        /// </summary>
        /// <param name="jsonNavigator">The navigator to use to navigate the node</param>
        /// <param name="jsonNavigatorNode">The node to write.</param>
        public void WriteJsonNode(IJsonNavigator jsonNavigator, IJsonNavigatorNode jsonNavigatorNode)
        {
            if (jsonNavigator == null)
            {
                throw new ArgumentNullException($"{nameof(jsonNavigator)} can not be null");
            }

            if (jsonNavigatorNode == null)
            {
                throw new ArgumentNullException($"{nameof(jsonNavigatorNode)} can not be null");
            }

            JsonNodeType jsonNodeType = jsonNavigator.GetNodeType(jsonNavigatorNode);

            // See if we can write the node without looking at it's value
            switch (jsonNodeType)
            {
            case JsonNodeType.Null:
                this.WriteNullValue();
                return;

            case JsonNodeType.False:
                this.WriteBoolValue(false);
                return;

            case JsonNodeType.True:
                this.WriteBoolValue(true);
                return;
            }

            bool sameFormat = jsonNavigator.SerializationFormat == this.SerializationFormat;

            // If the navigator has the same format as this writer then we try to retrieve the node raw JSON
            if (sameFormat && jsonNavigator.TryGetBufferedRawJson(jsonNavigatorNode, out ReadOnlyMemory <byte> bufferedRawJson))
            {
                // Token type really doesn't make any difference other than whether this is a field name
                JsonTokenType jsonTokenType = jsonNodeType == JsonNodeType.FieldName ? JsonTokenType.FieldName : JsonTokenType.Null;
                this.WriteRawJsonToken(jsonTokenType, bufferedRawJson.Span);
            }
            else
            {
                // Either the formats did not match or we couldn't retrieve the buffered raw JSON
                switch (jsonNodeType)
                {
                case JsonNodeType.Number64:
                    Number64 numberValue = jsonNavigator.GetNumber64Value(jsonNavigatorNode);
                    this.WriteNumber64Value(numberValue);
                    break;

                case JsonNodeType.String:
                case JsonNodeType.FieldName:
                    bool fieldName = jsonNodeType == JsonNodeType.FieldName;
                    if (jsonNavigator.TryGetBufferedUtf8StringValue(
                            jsonNavigatorNode,
                            out ReadOnlyMemory <byte> bufferedStringValue))
                    {
                        if (fieldName)
                        {
                            this.WriteFieldName(bufferedStringValue.Span);
                        }
                        else
                        {
                            this.WriteStringValue(bufferedStringValue.Span);
                        }
                    }
                    else
                    {
                        string value = jsonNavigator.GetStringValue(jsonNavigatorNode);
                        if (fieldName)
                        {
                            this.WriteFieldName(value);
                        }
                        else
                        {
                            this.WriteStringValue(value);
                        }
                    }

                    break;

                case JsonNodeType.Int8:
                {
                    sbyte number = jsonNavigator.GetInt8Value(jsonNavigatorNode);
                    this.WriteInt8Value(number);
                    break;
                }

                case JsonNodeType.Int16:
                {
                    short number = jsonNavigator.GetInt16Value(jsonNavigatorNode);
                    this.WriteInt16Value(number);
                    break;
                }

                case JsonNodeType.Int32:
                {
                    int number = jsonNavigator.GetInt32Value(jsonNavigatorNode);
                    this.WriteInt32Value(number);
                    break;
                }

                case JsonNodeType.Int64:
                {
                    long number = jsonNavigator.GetInt64Value(jsonNavigatorNode);
                    this.WriteInt64Value(number);
                    break;
                }

                case JsonNodeType.UInt32:
                {
                    uint number = jsonNavigator.GetUInt32Value(jsonNavigatorNode);
                    this.WriteUInt32Value(number);
                    break;
                }

                case JsonNodeType.Float32:
                {
                    float number = jsonNavigator.GetFloat32Value(jsonNavigatorNode);
                    this.WriteFloat32Value(number);
                    break;
                }

                case JsonNodeType.Float64:
                {
                    double number = jsonNavigator.GetFloat64Value(jsonNavigatorNode);
                    this.WriteFloat64Value(number);
                    break;
                }

                case JsonNodeType.Guid:
                {
                    Guid number = jsonNavigator.GetGuidValue(jsonNavigatorNode);
                    this.WriteGuidValue(number);
                    break;
                }

                case JsonNodeType.Binary:
                {
                    if (jsonNavigator.TryGetBufferedBinaryValue(jsonNavigatorNode, out ReadOnlyMemory <byte> bufferedBinaryValue))
                    {
                        this.WriteRawJsonToken(JsonTokenType.Binary, bufferedBinaryValue.Span);
                    }
                    else
                    {
                        ReadOnlyMemory <byte> value = jsonNavigator.GetBinaryValue(jsonNavigatorNode);
                        this.WriteBinaryValue(value.Span);
                    }

                    break;
                }

                case JsonNodeType.Array:
                    this.WriteArrayStart();
                    foreach (IJsonNavigatorNode arrayItem in jsonNavigator.GetArrayItems(jsonNavigatorNode))
                    {
                        this.WriteJsonNode(jsonNavigator, arrayItem);
                    }

                    this.WriteArrayEnd();
                    break;

                case JsonNodeType.Object:
                    this.WriteObjectStart();
                    foreach (ObjectProperty objectProperty in jsonNavigator.GetObjectProperties(jsonNavigatorNode))
                    {
                        this.WriteJsonNode(jsonNavigator, objectProperty.NameNode);
                        this.WriteJsonNode(jsonNavigator, objectProperty.ValueNode);
                    }

                    this.WriteObjectEnd();
                    break;

                default:
                    throw new ArgumentException($"Unexpected JsonNodeType: {jsonNodeType}");
                }
            }
        }