aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yson/node
diff options
context:
space:
mode:
authorlevysotsky <levysotsky@yandex-team.ru>2022-02-10 16:47:29 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:29 +0300
commit32b231c8474a1ade4bdf776ade6a20341691d9d7 (patch)
tree9814fbd1c3effac9b8377c5d604b367b14e2db55 /library/cpp/yson/node
parent57f874ffc2a75047c1c4fea7a9fc86cb0f56ed50 (diff)
downloadydb-32b231c8474a1ade4bdf776ade6a20341691d9d7.tar.gz
Restoring authorship annotation for <levysotsky@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/yson/node')
-rw-r--r--library/cpp/yson/node/node.cpp12
-rw-r--r--library/cpp/yson/node/node.h8
-rw-r--r--library/cpp/yson/node/node_io.cpp22
-rw-r--r--library/cpp/yson/node/node_io.h26
-rw-r--r--library/cpp/yson/node/node_ut.cpp24
-rw-r--r--library/cpp/yson/node/node_visitor.cpp72
-rw-r--r--library/cpp/yson/node/node_visitor.h2
-rw-r--r--library/cpp/yson/node/serialize.cpp182
-rw-r--r--library/cpp/yson/node/serialize.h42
-rw-r--r--library/cpp/yson/node/ya.make2
10 files changed, 196 insertions, 196 deletions
diff --git a/library/cpp/yson/node/node.cpp b/library/cpp/yson/node/node.cpp
index db507c2bb8..b39e070718 100644
--- a/library/cpp/yson/node/node.cpp
+++ b/library/cpp/yson/node/node.cpp
@@ -148,10 +148,10 @@ TNode::TNode(bool b)
: Value_(b)
{ }
-TNode::TNode(TMapType map)
+TNode::TNode(TMapType map)
: Value_(std::move(map))
-{ }
-
+{ }
+
TNode::TNode(const TNode& rhs)
: TNode()
{
@@ -259,7 +259,7 @@ bool TNode::Empty() const
case Map:
return std::get<TMapType>(Value_).empty();
default:
- ythrow TTypeError() << "Empty() called for type " << GetType();
+ ythrow TTypeError() << "Empty() called for type " << GetType();
}
}
@@ -273,7 +273,7 @@ size_t TNode::Size() const
case Map:
return std::get<TMapType>(Value_).size();
default:
- ythrow TTypeError() << "Size() called for type " << GetType();
+ ythrow TTypeError() << "Size() called for type " << GetType();
}
}
@@ -822,7 +822,7 @@ void TNode::Move(TNode&& rhs)
void TNode::CheckType(EType type) const
{
Y_ENSURE_EX(GetType() == type,
- TTypeError() << "TNode type " << type << " expected, actual type " << GetType();
+ TTypeError() << "TNode type " << type << " expected, actual type " << GetType();
);
}
diff --git a/library/cpp/yson/node/node.h b/library/cpp/yson/node/node.h
index bbf36144f6..5f90f95df0 100644
--- a/library/cpp/yson/node/node.h
+++ b/library/cpp/yson/node/node.h
@@ -101,7 +101,7 @@ public:
TNode(unsigned long long ui);
TNode(double d);
TNode(bool b);
- TNode(TMapType map);
+ TNode(TMapType map);
TNode(const TNode& rhs);
TNode& operator=(const TNode& rhs);
@@ -358,7 +358,7 @@ inline TString TNode::ConvertTo<TString>() const {
case NYT::TNode::Map:
case NYT::TNode::Null:
case NYT::TNode::Undefined:
- ythrow TTypeError() << "ConvertTo<TString>() called for type " << GetType();
+ ythrow TTypeError() << "ConvertTo<TString>() called for type " << GetType();
}
Y_UNREACHABLE();
}
@@ -380,7 +380,7 @@ inline double TNode::ConvertTo<double>() const {
case NYT::TNode::Map:
case NYT::TNode::Null:
case NYT::TNode::Undefined:
- ythrow TTypeError() << "ConvertTo<double>() called for type " << GetType();
+ ythrow TTypeError() << "ConvertTo<double>() called for type " << GetType();
}
}
@@ -401,7 +401,7 @@ inline bool TNode::ConvertTo<bool>() const {
case NYT::TNode::Map:
case NYT::TNode::Null:
case NYT::TNode::Undefined:
- ythrow TTypeError() << "ConvertTo<bool>() called for type " << GetType();
+ ythrow TTypeError() << "ConvertTo<bool>() called for type " << GetType();
}
}
diff --git a/library/cpp/yson/node/node_io.cpp b/library/cpp/yson/node/node_io.cpp
index e7eb6555ef..294a7f7217 100644
--- a/library/cpp/yson/node/node_io.cpp
+++ b/library/cpp/yson/node/node_io.cpp
@@ -96,12 +96,12 @@ TString NodeToYsonString(const TNode& node, NYson::EYsonFormat format)
}
TString NodeToCanonicalYsonString(const TNode& node, NYson::EYsonFormat format)
-{
- TStringStream stream;
- NodeToCanonicalYsonStream(node, &stream, format);
- return stream.Str();
-}
-
+{
+ TStringStream stream;
+ NodeToCanonicalYsonStream(node, &stream, format);
+ return stream.Str();
+}
+
TNode NodeFromYsonStream(IInputStream* input, ::NYson::EYsonType type)
{
TNode result = CreateEmptyNodeByType(type);
@@ -120,12 +120,12 @@ void NodeToYsonStream(const TNode& node, IOutputStream* output, NYson::EYsonForm
}
void NodeToCanonicalYsonStream(const TNode& node, IOutputStream* output, NYson::EYsonFormat format)
-{
+{
::NYson::TYsonWriter writer(output, format);
- TNodeVisitor visitor(&writer, /*sortMapKeys*/ true);
- visitor.Visit(node);
-}
-
+ TNodeVisitor visitor(&writer, /*sortMapKeys*/ true);
+ visitor.Visit(node);
+}
+
TNode NodeFromJsonString(const TStringBuf input)
{
TMemoryInput stream(input);
diff --git a/library/cpp/yson/node/node_io.h b/library/cpp/yson/node/node_io.h
index cdab595044..2ad23b658f 100644
--- a/library/cpp/yson/node/node_io.h
+++ b/library/cpp/yson/node/node_io.h
@@ -11,28 +11,28 @@ namespace NYT {
////////////////////////////////////////////////////////////////////////////////
-// Parse TNode from string in YSON format
+// Parse TNode from string in YSON format
TNode NodeFromYsonString(const TStringBuf input, ::NYson::EYsonType type = ::NYson::EYsonType::Node);
-
-// Serialize TNode to string in one of YSON formats with random order of maps' keys (don't use in tests)
+
+// Serialize TNode to string in one of YSON formats with random order of maps' keys (don't use in tests)
TString NodeToYsonString(const TNode& node, ::NYson::EYsonFormat format = ::NYson::EYsonFormat::Text);
-// Same as the latter, but maps' keys are sorted lexicographically (to be used in tests)
+// Same as the latter, but maps' keys are sorted lexicographically (to be used in tests)
TString NodeToCanonicalYsonString(const TNode& node, ::NYson::EYsonFormat format = ::NYson::EYsonFormat::Text);
-
-// Parse TNode from stream in YSON format
+
+// Parse TNode from stream in YSON format
TNode NodeFromYsonStream(IInputStream* input, ::NYson::EYsonType type = ::NYson::EYsonType::Node);
-
-// Serialize TNode to stream in one of YSON formats with random order of maps' keys (don't use in tests)
+
+// Serialize TNode to stream in one of YSON formats with random order of maps' keys (don't use in tests)
void NodeToYsonStream(const TNode& node, IOutputStream* output, ::NYson::EYsonFormat format = ::NYson::EYsonFormat::Text);
-// Same as the latter, but maps' keys are sorted lexicographically (to be used in tests)
+// Same as the latter, but maps' keys are sorted lexicographically (to be used in tests)
void NodeToCanonicalYsonStream(const TNode& node, IOutputStream* output, ::NYson::EYsonFormat format = ::NYson::EYsonFormat::Text);
-
-// Parse TNode from string in JSON format
+
+// Parse TNode from string in JSON format
TNode NodeFromJsonString(const TStringBuf input);
-
-// Convert TJsonValue to TNode
+
+// Convert TJsonValue to TNode
TNode NodeFromJsonValue(const NJson::TJsonValue& input);
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/yson/node/node_ut.cpp b/library/cpp/yson/node/node_ut.cpp
index 0235364c39..448e99f575 100644
--- a/library/cpp/yson/node/node_ut.cpp
+++ b/library/cpp/yson/node/node_ut.cpp
@@ -382,19 +382,19 @@ Y_UNIT_TEST_SUITE(YtNodeTest) {
UNIT_ASSERT_EXCEPTION(TNode("random").ConvertTo<bool>(), TFromStringException);
UNIT_ASSERT_EXCEPTION(TNode("").ConvertTo<bool>(), TFromStringException);
}
-
+
Y_UNIT_TEST(TestCanonicalSerialization) {
- auto node = TNode()
- ("ca", "ca")("c", "c")("a", "a")("b", "b")
- ("bb", TNode()
- ("ii", "ii")("i", "i")("jj", "jj"));
- node.Attributes() = TNode()("za", "za")("z", "z")("xxx", "xxx")("xx", "xx");
- UNIT_ASSERT_VALUES_EQUAL(NodeToCanonicalYsonString(node),
- "<\"xx\"=\"xx\";\"xxx\"=\"xxx\";\"z\"=\"z\";\"za\"=\"za\">"
- "{\"a\"=\"a\";\"b\"=\"b\";\"bb\"="
- "{\"i\"=\"i\";\"ii\"=\"ii\";\"jj\"=\"jj\"};"
- "\"c\"=\"c\";\"ca\"=\"ca\"}");
- }
+ auto node = TNode()
+ ("ca", "ca")("c", "c")("a", "a")("b", "b")
+ ("bb", TNode()
+ ("ii", "ii")("i", "i")("jj", "jj"));
+ node.Attributes() = TNode()("za", "za")("z", "z")("xxx", "xxx")("xx", "xx");
+ UNIT_ASSERT_VALUES_EQUAL(NodeToCanonicalYsonString(node),
+ "<\"xx\"=\"xx\";\"xxx\"=\"xxx\";\"z\"=\"z\";\"za\"=\"za\">"
+ "{\"a\"=\"a\";\"b\"=\"b\";\"bb\"="
+ "{\"i\"=\"i\";\"ii\"=\"ii\";\"jj\"=\"jj\"};"
+ "\"c\"=\"c\";\"ca\"=\"ca\"}");
+ }
Y_UNIT_TEST(OperatorEqualSubnode) {
TNode node;
diff --git a/library/cpp/yson/node/node_visitor.cpp b/library/cpp/yson/node/node_visitor.cpp
index 98b7c949d8..899fbfa02a 100644
--- a/library/cpp/yson/node/node_visitor.cpp
+++ b/library/cpp/yson/node/node_visitor.cpp
@@ -1,38 +1,38 @@
#include "node_visitor.h"
-#include <util/generic/algorithm.h>
+#include <util/generic/algorithm.h>
#include <util/string/printf.h>
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
-namespace {
-
-template <typename Fun>
-void Iterate(const TNode::TMapType& nodeMap, bool sortByKey, Fun action)
-{
- if (sortByKey) {
- TVector<TNode::TMapType::const_iterator> iterators;
- for (auto it = nodeMap.begin(); it != nodeMap.end(); ++it) {
- iterators.push_back(it);
- }
- SortBy(iterators, [](TNode::TMapType::const_iterator it) { return it->first; });
- for (const auto& it : iterators) {
- action(*it);
- }
- } else {
- ForEach(nodeMap.begin(), nodeMap.end(), action);
- }
-}
-
-} // namespace
-
-////////////////////////////////////////////////////////////////////////////////
-
+namespace {
+
+template <typename Fun>
+void Iterate(const TNode::TMapType& nodeMap, bool sortByKey, Fun action)
+{
+ if (sortByKey) {
+ TVector<TNode::TMapType::const_iterator> iterators;
+ for (auto it = nodeMap.begin(); it != nodeMap.end(); ++it) {
+ iterators.push_back(it);
+ }
+ SortBy(iterators, [](TNode::TMapType::const_iterator it) { return it->first; });
+ for (const auto& it : iterators) {
+ action(*it);
+ }
+ } else {
+ ForEach(nodeMap.begin(), nodeMap.end(), action);
+ }
+}
+
+} // namespace
+
+////////////////////////////////////////////////////////////////////////////////
+
TNodeVisitor::TNodeVisitor(NYson::IYsonConsumer* consumer, bool sortMapKeys)
: Consumer_(consumer)
- , SortMapKeys_(sortMapKeys)
+ , SortMapKeys_(sortMapKeys)
{ }
void TNodeVisitor::Visit(const TNode& node)
@@ -44,14 +44,14 @@ void TNodeVisitor::VisitAny(const TNode& node)
{
if (node.HasAttributes()) {
Consumer_->OnBeginAttributes();
- Iterate(node.GetAttributes().AsMap(), SortMapKeys_, [&](const std::pair<TString, TNode>& item) {
+ Iterate(node.GetAttributes().AsMap(), SortMapKeys_, [&](const std::pair<TString, TNode>& item) {
Consumer_->OnKeyedItem(item.first);
if (item.second.IsUndefined()) {
- ythrow TNode::TTypeError() << "unable to visit attribute value of type "
- << TNode::EType::Undefined << "; attribute name: `" << item.first << '\'' ;
+ ythrow TNode::TTypeError() << "unable to visit attribute value of type "
+ << TNode::EType::Undefined << "; attribute name: `" << item.first << '\'' ;
}
VisitAny(item.second);
- });
+ });
Consumer_->OnEndAttributes();
}
@@ -81,7 +81,7 @@ void TNodeVisitor::VisitAny(const TNode& node)
VisitEntity();
break;
case TNode::Undefined:
- ythrow TNode::TTypeError() << "unable to visit TNode of type " << node.GetType();
+ ythrow TNode::TTypeError() << "unable to visit TNode of type " << node.GetType();
default:
Y_FAIL("Unexpected type: %d", node.GetType());
}
@@ -119,8 +119,8 @@ void TNodeVisitor::VisitList(const TNode::TListType& nodeList)
for (const auto& item : nodeList) {
Consumer_->OnListItem();
if (item.IsUndefined()) {
- ythrow TNode::TTypeError() << "unable to visit list node child of type "
- << TNode::EType::Undefined << "; list index: " << index;
+ ythrow TNode::TTypeError() << "unable to visit list node child of type "
+ << TNode::EType::Undefined << "; list index: " << index;
}
VisitAny(item);
++index;
@@ -131,14 +131,14 @@ void TNodeVisitor::VisitList(const TNode::TListType& nodeList)
void TNodeVisitor::VisitMap(const TNode::TMapType& nodeMap)
{
Consumer_->OnBeginMap();
- Iterate(nodeMap, SortMapKeys_, [&](const std::pair<TString, TNode>& item) {
+ Iterate(nodeMap, SortMapKeys_, [&](const std::pair<TString, TNode>& item) {
Consumer_->OnKeyedItem(item.first);
if (item.second.IsUndefined()) {
- ythrow TNode::TTypeError() << "unable to visit map node child of type "
- << TNode::EType::Undefined << "; map key: `" << item.first << '\'' ;
+ ythrow TNode::TTypeError() << "unable to visit map node child of type "
+ << TNode::EType::Undefined << "; map key: `" << item.first << '\'' ;
}
VisitAny(item.second);
- });
+ });
Consumer_->OnEndMap();
}
diff --git a/library/cpp/yson/node/node_visitor.h b/library/cpp/yson/node/node_visitor.h
index 6dd4b8a5b4..db25832309 100644
--- a/library/cpp/yson/node/node_visitor.h
+++ b/library/cpp/yson/node/node_visitor.h
@@ -19,7 +19,7 @@ public:
private:
NYson::IYsonConsumer* Consumer_;
- bool SortMapKeys_;
+ bool SortMapKeys_;
private:
void VisitAny(const TNode& node);
diff --git a/library/cpp/yson/node/serialize.cpp b/library/cpp/yson/node/serialize.cpp
index f65c599186..aeb467622b 100644
--- a/library/cpp/yson/node/serialize.cpp
+++ b/library/cpp/yson/node/serialize.cpp
@@ -1,101 +1,101 @@
-#include "serialize.h"
-
+#include "serialize.h"
+
#include "node_visitor.h"
-
+
#include <library/cpp/yson/consumer.h>
-
-namespace NYT {
-
-////////////////////////////////////////////////////////////////////////////////
-
+
+namespace NYT {
+
+////////////////////////////////////////////////////////////////////////////////
+
void Serialize(const TString& value, NYson::IYsonConsumer* consumer)
-{
- consumer->OnStringScalar(value);
-}
-
+{
+ consumer->OnStringScalar(value);
+}
+
void Serialize(const TStringBuf& value, NYson::IYsonConsumer* consumer)
-{
- consumer->OnStringScalar(value);
-}
-
+{
+ consumer->OnStringScalar(value);
+}
+
void Serialize(const char* value, NYson::IYsonConsumer* consumer)
-{
- consumer->OnStringScalar(value);
-}
-
-void Deserialize(TString& value, const TNode& node)
-{
- value = node.AsString();
-}
-
-#define SERIALIZE_SIGNED(type) \
+{
+ consumer->OnStringScalar(value);
+}
+
+void Deserialize(TString& value, const TNode& node)
+{
+ value = node.AsString();
+}
+
+#define SERIALIZE_SIGNED(type) \
void Serialize(type value, NYson::IYsonConsumer* consumer) \
-{ \
- consumer->OnInt64Scalar(static_cast<i64>(value)); \
-}
-
-#define SERIALIZE_UNSIGNED(type) \
+{ \
+ consumer->OnInt64Scalar(static_cast<i64>(value)); \
+}
+
+#define SERIALIZE_UNSIGNED(type) \
void Serialize(type value, NYson::IYsonConsumer* consumer) \
-{ \
- consumer->OnUint64Scalar(static_cast<ui64>(value)); \
-}
-
-SERIALIZE_SIGNED(signed char);
-SERIALIZE_SIGNED(short);
-SERIALIZE_SIGNED(int);
-SERIALIZE_SIGNED(long);
-SERIALIZE_SIGNED(long long);
-
-SERIALIZE_UNSIGNED(unsigned char);
-SERIALIZE_UNSIGNED(unsigned short);
-SERIALIZE_UNSIGNED(unsigned int);
-SERIALIZE_UNSIGNED(unsigned long);
-SERIALIZE_UNSIGNED(unsigned long long);
-
-#undef SERIALIZE_SIGNED
-#undef SERIALIZE_UNSIGNED
-
-void Deserialize(i64& value, const TNode& node)
-{
- value = node.AsInt64();
-}
-
-void Deserialize(ui64& value, const TNode& node)
-{
- value = node.AsUint64();
-}
-
+{ \
+ consumer->OnUint64Scalar(static_cast<ui64>(value)); \
+}
+
+SERIALIZE_SIGNED(signed char);
+SERIALIZE_SIGNED(short);
+SERIALIZE_SIGNED(int);
+SERIALIZE_SIGNED(long);
+SERIALIZE_SIGNED(long long);
+
+SERIALIZE_UNSIGNED(unsigned char);
+SERIALIZE_UNSIGNED(unsigned short);
+SERIALIZE_UNSIGNED(unsigned int);
+SERIALIZE_UNSIGNED(unsigned long);
+SERIALIZE_UNSIGNED(unsigned long long);
+
+#undef SERIALIZE_SIGNED
+#undef SERIALIZE_UNSIGNED
+
+void Deserialize(i64& value, const TNode& node)
+{
+ value = node.AsInt64();
+}
+
+void Deserialize(ui64& value, const TNode& node)
+{
+ value = node.AsUint64();
+}
+
void Serialize(double value, NYson::IYsonConsumer* consumer)
-{
- consumer->OnDoubleScalar(value);
-}
-
-void Deserialize(double& value, const TNode& node)
-{
- value = node.AsDouble();
-}
-
+{
+ consumer->OnDoubleScalar(value);
+}
+
+void Deserialize(double& value, const TNode& node)
+{
+ value = node.AsDouble();
+}
+
void Serialize(bool value, NYson::IYsonConsumer* consumer)
-{
- consumer->OnBooleanScalar(value);
-}
-
-void Deserialize(bool& value, const TNode& node)
-{
- value = node.AsBool();
-}
-
+{
+ consumer->OnBooleanScalar(value);
+}
+
+void Deserialize(bool& value, const TNode& node)
+{
+ value = node.AsBool();
+}
+
void Serialize(const TNode& node, NYson::IYsonConsumer* consumer)
-{
- TNodeVisitor visitor(consumer);
- visitor.Visit(node);
-}
-
-void Deserialize(TNode& value, const TNode& node)
-{
- value = node;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace NYT
+{
+ TNodeVisitor visitor(consumer);
+ visitor.Visit(node);
+}
+
+void Deserialize(TNode& value, const TNode& node)
+{
+ value = node;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT
diff --git a/library/cpp/yson/node/serialize.h b/library/cpp/yson/node/serialize.h
index 5fc72a0482..99b598a44c 100644
--- a/library/cpp/yson/node/serialize.h
+++ b/library/cpp/yson/node/serialize.h
@@ -1,45 +1,45 @@
-#pragma once
-
-#include "node.h"
-
+#pragma once
+
+#include "node.h"
+
namespace NYT {
namespace NYson {
struct IYsonConsumer;
} // namespace NYson
-////////////////////////////////////////////////////////////////////////////////
-
+////////////////////////////////////////////////////////////////////////////////
+
void Serialize(const TString& value, NYson::IYsonConsumer* consumer);
void Serialize(const TStringBuf& value, NYson::IYsonConsumer* consumer);
void Serialize(const char* value, NYson::IYsonConsumer* consumer);
-void Deserialize(TString& value, const TNode& node);
-
+void Deserialize(TString& value, const TNode& node);
+
void Serialize(signed char value, NYson::IYsonConsumer* consumer);
void Serialize(short value, NYson::IYsonConsumer* consumer);
void Serialize(int value, NYson::IYsonConsumer* consumer);
void Serialize(long value, NYson::IYsonConsumer* consumer);
void Serialize(long long value, NYson::IYsonConsumer* consumer);
-void Deserialize(i64& value, const TNode& node);
-
+void Deserialize(i64& value, const TNode& node);
+
void Serialize(unsigned char value, NYson::IYsonConsumer* consumer);
void Serialize(unsigned short value, NYson::IYsonConsumer* consumer);
void Serialize(unsigned int value, NYson::IYsonConsumer* consumer);
void Serialize(unsigned long value, NYson::IYsonConsumer* consumer);
void Serialize(unsigned long long value, NYson::IYsonConsumer* consumer);
-void Deserialize(ui64& value, const TNode& node);
-
+void Deserialize(ui64& value, const TNode& node);
+
void Serialize(double value, NYson::IYsonConsumer* consumer);
-void Deserialize(double& value, const TNode& node);
-
+void Deserialize(double& value, const TNode& node);
+
void Serialize(bool value, NYson::IYsonConsumer* consumer);
-void Deserialize(bool& value, const TNode& node);
-
+void Deserialize(bool& value, const TNode& node);
+
void Serialize(const TNode& node, NYson::IYsonConsumer* consumer);
-void Deserialize(TNode& value, const TNode& node);
-
+void Deserialize(TNode& value, const TNode& node);
+
void Serialize(const THashMap<TString, TString>& renameColumns, NYson::IYsonConsumer* consumer);
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace NYT
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT
diff --git a/library/cpp/yson/node/ya.make b/library/cpp/yson/node/ya.make
index 7b96a1e634..a082b293c4 100644
--- a/library/cpp/yson/node/ya.make
+++ b/library/cpp/yson/node/ya.make
@@ -17,7 +17,7 @@ SRCS(
node_io.cpp
node_builder.cpp
node_visitor.cpp
- serialize.cpp
+ serialize.cpp
)
END()