diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/yson/node/serialize.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/yson/node/serialize.cpp')
-rw-r--r-- | library/cpp/yson/node/serialize.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/library/cpp/yson/node/serialize.cpp b/library/cpp/yson/node/serialize.cpp new file mode 100644 index 0000000000..aeb467622b --- /dev/null +++ b/library/cpp/yson/node/serialize.cpp @@ -0,0 +1,101 @@ +#include "serialize.h" + +#include "node_visitor.h" + +#include <library/cpp/yson/consumer.h> + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + +void Serialize(const TString& value, NYson::IYsonConsumer* consumer) +{ + consumer->OnStringScalar(value); +} + +void Serialize(const TStringBuf& value, NYson::IYsonConsumer* consumer) +{ + 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) \ +void Serialize(type value, NYson::IYsonConsumer* consumer) \ +{ \ + 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(); +} + +void Serialize(double value, NYson::IYsonConsumer* consumer) +{ + 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(); +} + +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 |