From 1110808a9d39d4b808aef724c861a2e1a38d2a69 Mon Sep 17 00:00:00 2001
From: Devtools Arcadia <arcadia-devtools@yandex-team.ru>
Date: Mon, 7 Feb 2022 18:08:42 +0300
Subject: intermediate changes ref:cde9a383711a11544ce7e107a78147fb96cc4029

---
 library/cpp/protobuf/json/json_value_output.h | 63 +++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 library/cpp/protobuf/json/json_value_output.h

(limited to 'library/cpp/protobuf/json/json_value_output.h')

diff --git a/library/cpp/protobuf/json/json_value_output.h b/library/cpp/protobuf/json/json_value_output.h
new file mode 100644
index 0000000000..3fc6ff2ab0
--- /dev/null
+++ b/library/cpp/protobuf/json/json_value_output.h
@@ -0,0 +1,63 @@
+#pragma once
+
+#include "json_output.h"
+
+#include <library/cpp/json/writer/json_value.h>
+
+#include <util/generic/stack.h>
+
+namespace NProtobufJson {
+    class TJsonValueOutput: public IJsonOutput {
+    public:
+        TJsonValueOutput(NJson::TJsonValue& value)
+            : Root(value)
+        {
+            Context.emplace(TContext::JSON_AFTER_KEY, Root);
+        }
+
+        void DoWrite(const TStringBuf& s) override;
+        void DoWrite(const TString& s) override;
+        void DoWrite(int i) override;
+        void DoWrite(unsigned int i) override;
+        void DoWrite(long long i) override;
+        void DoWrite(unsigned long long i) override;
+        void DoWrite(float f) override;
+        void DoWrite(double f) override;
+        void DoWrite(bool b) override;
+        void DoWriteNull() override;
+
+        void DoBeginList() override;
+        void DoEndList() override;
+
+        void DoBeginObject() override;
+        void DoWriteKey(const TStringBuf& key) override;
+        void DoEndObject() override;
+
+        void DoWriteRawJson(const TStringBuf& str) override;
+
+    private:
+        template <typename T>
+        void WriteImpl(const T& t);
+
+        struct TContext {
+            enum EType {
+                JSON_MAP,
+                JSON_ARRAY,
+                JSON_AFTER_KEY,
+            };
+
+            TContext(EType type, NJson::TJsonValue& value)
+                : Type(type)
+                , Value(value)
+            {
+            }
+
+            EType Type;
+            NJson::TJsonValue& Value;
+        };
+
+        NJson::TJsonValue& Root;
+        TStack<TContext, TVector<TContext>> Context;
+    };
+
+}
-- 
cgit v1.2.3