aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yson/writer.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/yson/writer.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/yson/writer.h')
-rw-r--r--library/cpp/yson/writer.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/library/cpp/yson/writer.h b/library/cpp/yson/writer.h
new file mode 100644
index 00000000000..40f5d7d5014
--- /dev/null
+++ b/library/cpp/yson/writer.h
@@ -0,0 +1,89 @@
+#pragma once
+
+#include "public.h"
+#include "token.h"
+#include "consumer.h"
+
+#include <util/generic/noncopyable.h>
+
+class IOutputStream;
+class IZeroCopyInput;
+
+namespace NYson {
+ ////////////////////////////////////////////////////////////////////////////////
+
+ class TYsonWriter
+ : public TYsonConsumerBase,
+ private TNonCopyable {
+ public:
+ class TState {
+ private:
+ int Depth;
+ bool BeforeFirstItem;
+
+ friend class TYsonWriter;
+ };
+
+ public:
+ TYsonWriter(
+ IOutputStream* stream,
+ EYsonFormat format = EYsonFormat::Binary,
+ EYsonType type = ::NYson::EYsonType::Node,
+ bool enableRaw = false);
+
+ void OnStringScalar(TStringBuf value) override;
+ void OnInt64Scalar(i64 value) override;
+ void OnUint64Scalar(ui64 value) override;
+ void OnDoubleScalar(double value) override;
+ void OnBooleanScalar(bool value) override;
+ void OnEntity() override;
+
+ void OnBeginList() override;
+ void OnListItem() override;
+ void OnEndList() override;
+
+ void OnBeginMap() override;
+ void OnKeyedItem(TStringBuf key) override;
+ void OnEndMap() override;
+
+ void OnBeginAttributes() override;
+ void OnEndAttributes() override;
+
+ void OnRaw(TStringBuf yson, EYsonType type = ::NYson::EYsonType::Node) override;
+
+ TState State() const;
+ void Reset(const TState& state);
+
+ protected:
+ IOutputStream* Stream;
+ EYsonFormat Format;
+ EYsonType Type;
+ bool EnableRaw;
+
+ int Depth;
+ bool BeforeFirstItem;
+
+ static const int IndentSize = 4;
+
+ void WriteIndent();
+ void WriteStringScalar(const TStringBuf& value);
+
+ void BeginCollection(ETokenType beginToken);
+ void CollectionItem(ETokenType separatorToken);
+ void EndCollection(ETokenType endToken);
+
+ bool IsTopLevelFragmentContext() const;
+ void EndNode();
+ };
+
+ ////////////////////////////////////////////////////////////////////////////////
+
+ void ReformatYsonStream(
+ IInputStream* input,
+ IOutputStream* output,
+ EYsonFormat format = EYsonFormat::Binary,
+ EYsonType type = ::NYson::EYsonType::Node);
+
+ ////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYson