aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yson/json/json_writer.cpp
diff options
context:
space:
mode:
authormonster <monster@yandex-team.ru>2022-02-10 16:47:19 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:19 +0300
commitdd76ae1f6213d065375ab296699f764faafbe5bd (patch)
tree075a4553d0011d8f92752c0891794febb15912cf /library/cpp/yson/json/json_writer.cpp
parentf02a874a7290593efbe4b3aeae69a04b46c1cc86 (diff)
downloadydb-dd76ae1f6213d065375ab296699f764faafbe5bd.tar.gz
Restoring authorship annotation for <monster@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/yson/json/json_writer.cpp')
-rw-r--r--library/cpp/yson/json/json_writer.cpp104
1 files changed, 52 insertions, 52 deletions
diff --git a/library/cpp/yson/json/json_writer.cpp b/library/cpp/yson/json/json_writer.cpp
index 87481256ec..2c961a02fa 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();
}
-
+
////////////////////////////////////////////////////////////////////////////////
-}
+}