private void WriteToInternal()

in Microsoft.Azure.Cosmos/src/Json/JsonNavigator.JsonBinaryNavigator.cs [476:633]


            private void WriteToInternal(BinaryNavigatorNode binaryNavigatorNode, IJsonWriter jsonWriter)
            {
                ReadOnlyMemory<byte> buffer = this.rootBuffer.Slice(binaryNavigatorNode.Offset);
                JsonNodeType nodeType = binaryNavigatorNode.NodeType;

                switch (nodeType)
                {
                    case JsonNodeType.Null:
                        jsonWriter.WriteNullValue();
                        break;

                    case JsonNodeType.False:
                        jsonWriter.WriteBoolValue(false);
                        break;

                    case JsonNodeType.True:
                        jsonWriter.WriteBoolValue(true);
                        break;

                    case JsonNodeType.Number:
                        if (JsonBinaryEncoding.TryGetUInt64Value(buffer.Span, binaryNavigatorNode.ExternalArrayInfo, out ulong uint64Value))
                        {
                            jsonWriter.WriteNumberValue(uint64Value);
                        }
                        else
                        {
                            Number64 value = JsonBinaryEncoding.GetNumberValue(buffer.Span, binaryNavigatorNode.ExternalArrayInfo);
                            jsonWriter.WriteNumberValue(value);
                        }
                        break;

                    case JsonNodeType.String:
                    case JsonNodeType.FieldName:
                        bool fieldName = binaryNavigatorNode.NodeType == JsonNodeType.FieldName;

                        if (JsonBinaryEncoding.TryGetBufferedStringValue(
                            this.rootBuffer,
                            buffer,
                            this.jsonStringDictionary,
                            out Utf8Memory bufferedStringValue))
                        {
                            if (fieldName)
                            {
                                jsonWriter.WriteFieldName(bufferedStringValue.Span);
                            }
                            else
                            {
                                jsonWriter.WriteStringValue(bufferedStringValue.Span);
                            }
                        }
                        else
                        {
                            string value = JsonBinaryEncoding.GetStringValue(this.rootBuffer, buffer, this.jsonStringDictionary);
                            if (fieldName)
                            {
                                jsonWriter.WriteFieldName(value);
                            }
                            else
                            {
                                jsonWriter.WriteStringValue(value);
                            }
                        }
                        break;

                    case JsonNodeType.Array:
                        {
                            jsonWriter.WriteArrayStart();

                            foreach (BinaryNavigatorNode arrayItem in this.GetArrayItemsInternal(binaryNavigatorNode))
                            {
                                this.WriteToInternal(arrayItem, jsonWriter);
                            }

                            jsonWriter.WriteArrayEnd();
                        }
                        break;

                    case JsonNodeType.Object:
                        {
                            jsonWriter.WriteObjectStart();

                            foreach (ObjectPropertyInternal objectProperty in this.GetObjectPropertiesInternal(binaryNavigatorNode))
                            {
                                this.WriteToInternal(objectProperty.NameNode, jsonWriter);
                                this.WriteToInternal(objectProperty.ValueNode, jsonWriter);
                            }

                            jsonWriter.WriteObjectEnd();
                        }
                        break;

                    case JsonNodeType.Int8:
                        {
                            sbyte value = JsonBinaryEncoding.GetInt8Value(buffer.Span);
                            jsonWriter.WriteInt8Value(value);
                        }
                        break;

                    case JsonNodeType.Int16:
                        {
                            short value = JsonBinaryEncoding.GetInt16Value(buffer.Span);
                            jsonWriter.WriteInt16Value(value);
                        }
                        break;

                    case JsonNodeType.Int32:
                        {
                            int value = JsonBinaryEncoding.GetInt32Value(buffer.Span);
                            jsonWriter.WriteInt32Value(value);
                        }
                        break;

                    case JsonNodeType.Int64:
                        {
                            long value = JsonBinaryEncoding.GetInt64Value(buffer.Span);
                            jsonWriter.WriteInt64Value(value);
                        }
                        break;

                    case JsonNodeType.UInt32:
                        {
                            uint value = JsonBinaryEncoding.GetUInt32Value(buffer.Span);
                            jsonWriter.WriteUInt32Value(value);
                        }
                        break;

                    case JsonNodeType.Float32:
                        {
                            float value = JsonBinaryEncoding.GetFloat32Value(buffer.Span);
                            jsonWriter.WriteFloat32Value(value);
                        }
                        break;

                    case JsonNodeType.Float64:
                        {
                            double value = JsonBinaryEncoding.GetFloat64Value(buffer.Span);
                            jsonWriter.WriteFloat64Value(value);
                        }
                        break;

                    case JsonNodeType.Binary:
                        {
                            ReadOnlyMemory<byte> value = JsonBinaryEncoding.GetBinaryValue(buffer);
                            jsonWriter.WriteBinaryValue(value.Span);
                        }
                        break;

                    case JsonNodeType.Guid:
                        {
                            Guid value = JsonBinaryEncoding.GetGuidValue(buffer.Span);
                            jsonWriter.WriteGuidValue(value);
                        }
                        break;

                    default:
                        throw new ArgumentOutOfRangeException($"Unknown {nameof(JsonNodeType)}: {nodeType}.");
                }
            }