diff options
author | monster <monster@yandex-team.ru> | 2022-02-10 16:47:19 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:19 +0300 |
commit | dd76ae1f6213d065375ab296699f764faafbe5bd (patch) | |
tree | 075a4553d0011d8f92752c0891794febb15912cf /library/cpp/yson/json | |
parent | f02a874a7290593efbe4b3aeae69a04b46c1cc86 (diff) | |
download | ydb-dd76ae1f6213d065375ab296699f764faafbe5bd.tar.gz |
Restoring authorship annotation for <monster@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/yson/json')
-rw-r--r-- | library/cpp/yson/json/json_writer.cpp | 104 | ||||
-rw-r--r-- | library/cpp/yson/json/json_writer.h | 44 |
2 files changed, 74 insertions, 74 deletions
diff --git a/library/cpp/yson/json/json_writer.cpp b/library/cpp/yson/json/json_writer.cpp index 87481256ecd..2c961a02fa8 100644 --- a/library/cpp/yson/json/json_writer.cpp +++ b/library/cpp/yson/json/json_writer.cpp @@ -1,16 +1,16 @@ -#include "json_writer.h" - +#include "json_writer.h" + #include <library/cpp/json/json_writer.h> - -namespace NYT { + +namespace NYT { //////////////////////////////////////////////////////////////////////////////// - + static bool IsSpecialJsonKey(const TStringBuf& key) { return key.size() > 0 && key[0] == '$'; } - + //////////////////////////////////////////////////////////////////////////////// - + TJsonWriter::TJsonWriter( IOutputStream* output, ::NYson::EYsonType type, @@ -41,15 +41,15 @@ namespace NYT { if (Type == ::NYson::EYsonType::MapFragment) { ythrow ::NYson::TYsonException() << ("Map fragments are not supported by Json"); } - + UnderlyingJsonWriter.Reset(new NJson::TJsonWriter( output, config)); JsonWriter = UnderlyingJsonWriter.Get(); HasAttributes = false; InAttributesBalance = 0; - } - + } + void TJsonWriter::EnterNode() { if (AttributesMode == JAM_NEVER) { HasAttributes = false; @@ -65,15 +65,15 @@ namespace NYT { HasAttributes = true; } HasUnfoldedStructureStack.push_back(HasAttributes); - + if (HasAttributes) { JsonWriter->Write("$value"); HasAttributes = false; - } - + } + Depth += 1; - } - + } + void TJsonWriter::LeaveNode() { Y_ASSERT(!HasUnfoldedStructureStack.empty()); if (HasUnfoldedStructureStack.back()) { @@ -81,54 +81,54 @@ namespace NYT { JsonWriter->CloseMap(); } HasUnfoldedStructureStack.pop_back(); - + Depth -= 1; if (Depth == 0 && Type == ::NYson::EYsonType::ListFragment && InAttributesBalance == 0) { JsonWriter->Flush(); Output->Write("\n"); } - } - + } + bool TJsonWriter::IsWriteAllowed() { if (AttributesMode == JAM_NEVER) { return InAttributesBalance == 0; } return true; - } - + } + void TJsonWriter::OnStringScalar(TStringBuf value) { if (IsWriteAllowed()) { EnterNode(); WriteStringScalar(value); LeaveNode(); } - } - + } + void TJsonWriter::OnInt64Scalar(i64 value) { if (IsWriteAllowed()) { EnterNode(); JsonWriter->Write(value); LeaveNode(); } - } - + } + void TJsonWriter::OnUint64Scalar(ui64 value) { if (IsWriteAllowed()) { EnterNode(); JsonWriter->Write(value); LeaveNode(); } - } - + } + void TJsonWriter::OnDoubleScalar(double value) { if (IsWriteAllowed()) { EnterNode(); JsonWriter->Write(value); LeaveNode(); } - } - + } + void TJsonWriter::OnBooleanScalar(bool value) { if (IsWriteAllowed()) { if (BooleanFormat == SBF_STRING) { @@ -139,40 +139,40 @@ namespace NYT { LeaveNode(); } } - } - + } + void TJsonWriter::OnEntity() { if (IsWriteAllowed()) { EnterNode(); JsonWriter->WriteNull(); LeaveNode(); } - } - + } + void TJsonWriter::OnBeginList() { if (IsWriteAllowed()) { EnterNode(); JsonWriter->OpenArray(); } - } - + } + void TJsonWriter::OnListItem() { - } - + } + void TJsonWriter::OnEndList() { if (IsWriteAllowed()) { JsonWriter->CloseArray(); LeaveNode(); } } - + void TJsonWriter::OnBeginMap() { if (IsWriteAllowed()) { EnterNode(); JsonWriter->OpenMap(); } - } - + } + void TJsonWriter::OnKeyedItem(TStringBuf name) { if (IsWriteAllowed()) { if (IsSpecialJsonKey(name)) { @@ -181,15 +181,15 @@ namespace NYT { WriteStringScalar(name); } } - } - + } + void TJsonWriter::OnEndMap() { if (IsWriteAllowed()) { JsonWriter->CloseMap(); LeaveNode(); - } - } - + } + } + void TJsonWriter::OnBeginAttributes() { InAttributesBalance += 1; if (AttributesMode != JAM_NEVER) { @@ -197,24 +197,24 @@ namespace NYT { JsonWriter->Write("$attributes"); JsonWriter->OpenMap(); } - } - + } + void TJsonWriter::OnEndAttributes() { InAttributesBalance -= 1; if (AttributesMode != JAM_NEVER) { HasAttributes = true; JsonWriter->CloseMap(); } - } - + } + void TJsonWriter::WriteStringScalar(const TStringBuf& value) { JsonWriter->Write(value); - } - + } + void TJsonWriter::Flush() { JsonWriter->Flush(); } - + //////////////////////////////////////////////////////////////////////////////// -} +} diff --git a/library/cpp/yson/json/json_writer.h b/library/cpp/yson/json/json_writer.h index d84ac0de530..43e5293b0d4 100644 --- a/library/cpp/yson/json/json_writer.h +++ b/library/cpp/yson/json/json_writer.h @@ -1,31 +1,31 @@ -#pragma once - +#pragma once + #include <library/cpp/yson/public.h> #include <library/cpp/yson/consumer.h> - + #include <library/cpp/json/json_writer.h> - -#include <util/generic/vector.h> - -namespace NYT { + +#include <util/generic/vector.h> + +namespace NYT { //////////////////////////////////////////////////////////////////////////////// - + enum EJsonFormat { JF_TEXT, JF_PRETTY }; - + enum EJsonAttributesMode { JAM_NEVER, JAM_ON_DEMAND, JAM_ALWAYS }; - + enum ESerializedBoolFormat { SBF_BOOLEAN, SBF_STRING }; - + class TJsonWriter : public ::NYson::TYsonConsumerBase { public: @@ -44,26 +44,26 @@ namespace NYT { ESerializedBoolFormat booleanFormat = SBF_STRING); void Flush(); - + 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; - + private: THolder<NJson::TJsonWriter> UnderlyingJsonWriter; NJson::TJsonWriter* JsonWriter; @@ -71,19 +71,19 @@ namespace NYT { ::NYson::EYsonType Type; EJsonAttributesMode AttributesMode; ESerializedBoolFormat BooleanFormat; - + void WriteStringScalar(const TStringBuf& value); - + void EnterNode(); void LeaveNode(); bool IsWriteAllowed(); - + TVector<bool> HasUnfoldedStructureStack; int InAttributesBalance; bool HasAttributes; int Depth; }; - + //////////////////////////////////////////////////////////////////////////////// - + } |