aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/protobuf/json/json_output.h
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/protobuf/json/json_output.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/protobuf/json/json_output.h')
-rw-r--r--library/cpp/protobuf/json/json_output.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/library/cpp/protobuf/json/json_output.h b/library/cpp/protobuf/json/json_output.h
new file mode 100644
index 0000000000..df143af57a
--- /dev/null
+++ b/library/cpp/protobuf/json/json_output.h
@@ -0,0 +1,79 @@
+#pragma once
+
+#include <util/generic/ptr.h>
+#include <util/generic/strbuf.h>
+
+namespace NProtobufJson {
+ class IJsonOutput {
+ public:
+ template <typename T>
+ IJsonOutput& Write(const T& t) {
+ DoWrite(t);
+ return *this;
+ }
+ IJsonOutput& WriteNull() {
+ DoWriteNull();
+ return *this;
+ }
+
+ IJsonOutput& BeginList() {
+ DoBeginList();
+ return *this;
+ }
+ IJsonOutput& EndList() {
+ DoEndList();
+ return *this;
+ }
+
+ IJsonOutput& BeginObject() {
+ DoBeginObject();
+ return *this;
+ }
+ IJsonOutput& WriteKey(const TStringBuf& key) {
+ DoWriteKey(key);
+ return *this;
+ }
+ IJsonOutput& EndObject() {
+ DoEndObject();
+ return *this;
+ }
+
+ IJsonOutput& WriteRawJson(const TStringBuf& str) {
+ DoWriteRawJson(str);
+ return *this;
+ }
+
+ virtual ~IJsonOutput() {
+ }
+
+ protected:
+ virtual void DoWrite(const TStringBuf& s) = 0;
+ virtual void DoWrite(const TString& s) = 0;
+ virtual void DoWrite(int i) = 0;
+ void DoWrite(long i) {
+ DoWrite(static_cast<long long>(i));
+ }
+ virtual void DoWrite(long long i) = 0;
+ virtual void DoWrite(unsigned int i) = 0;
+ void DoWrite(unsigned long i) {
+ DoWrite(static_cast<unsigned long long>(i));
+ }
+ virtual void DoWrite(unsigned long long i) = 0;
+ virtual void DoWrite(float f) = 0;
+ virtual void DoWrite(double f) = 0;
+ virtual void DoWrite(bool b) = 0;
+ virtual void DoWriteNull() = 0;
+
+ virtual void DoBeginList() = 0;
+ virtual void DoEndList() = 0;
+
+ virtual void DoBeginObject() = 0;
+ virtual void DoWriteKey(const TStringBuf& key) = 0;
+ virtual void DoEndObject() = 0;
+
+ virtual void DoWriteRawJson(const TStringBuf& str) = 0;
+ };
+
+ using TJsonMapOutputPtr = THolder<IJsonOutput>;
+
+}