diff options
| author | achains <[email protected]> | 2025-09-19 16:38:48 +0300 |
|---|---|---|
| committer | achains <[email protected]> | 2025-09-19 17:55:25 +0300 |
| commit | d5841aaecfd21f305a7aa02367410d9f3a673136 (patch) | |
| tree | 6c5cc394a1703b377cba64669905d32009256396 /yt/cpp/mapreduce/interface/serialize.h | |
| parent | b09133a16e8e579bc531af7083326b1ca5b1f0c0 (diff) | |
YT-26145: TConfig serialization
* Changelog entry
Type: feature
Component: cpp-sdk
Add serialization / deserialization methods for TConfig class
commit_hash:b8dbd0cb04aa88fb629e6f2b855a3e7b1bad0ded
Diffstat (limited to 'yt/cpp/mapreduce/interface/serialize.h')
| -rw-r--r-- | yt/cpp/mapreduce/interface/serialize.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/yt/cpp/mapreduce/interface/serialize.h b/yt/cpp/mapreduce/interface/serialize.h index 6127b808c77..8ed94a178a1 100644 --- a/yt/cpp/mapreduce/interface/serialize.h +++ b/yt/cpp/mapreduce/interface/serialize.h @@ -9,6 +9,10 @@ #include <library/cpp/yson/writer.h> +#include <util/datetime/base.h> + +#include <library/cpp/yt/misc/cast.h> + #include <library/cpp/type_info/fwd.h> namespace NYT::NYson { @@ -80,6 +84,7 @@ void Deserialize(TTableColumnarStatistics& statistics, const TNode& node); void Deserialize(TMultiTablePartition& partition, const TNode& node); void Deserialize(TMultiTablePartitions& partitions, const TNode& node); void Deserialize(TTabletInfo& tabletInfos, const TNode& node); +void Deserialize(TDuration& duration, const TNode& node); void Serialize(const TGUID& path, NYT::NYson::IYsonConsumer* consumer); void Deserialize(TGUID& value, const TNode& node); @@ -87,6 +92,41 @@ void Deserialize(TGUID& value, const TNode& node); void Serialize(const NTi::TTypePtr& type, NYT::NYson::IYsonConsumer* consumer); void Deserialize(NTi::TTypePtr& type, const TNode& node); +template <std::integral T> +void Deserialize(T& value, const TNode& node) +{ + if (node.GetType() == TNode::EType::Int64) { + value = CheckedIntegralCast<T>(node.AsInt64()); + } else if (node.GetType() == TNode::EType::Uint64) { + value = CheckedIntegralCast<T>(node.AsUint64()); + } else { + throw yexception() << "Cannot parse integral value from node of type " << node.GetType(); + } +} + +template <typename T> +void Deserialize(THashSet<T>& hs, const TNode& node) +{ + if (node.GetType() != TNode::EType::List) { + throw yexception() << "Cannot parse hashset from node of type " << node.GetType(); + } + for (const auto& value : node.AsList()) { + T deserialized; + Deserialize(deserialized, value); + hs.insert(deserialized); + } +} + +template <typename T> +requires std::is_enum_v<T> +void Deserialize(T& value, const TNode& node) +{ + if (auto nodeType = node.GetType(); nodeType != TNode::EType::String) { + throw yexception() << "Enum deserialization expects EType::String, got " << node.GetType(); + } + value = ::FromString<T>(node.AsString()); +} + template <typename T> TString ToYsonText(const T& value) { |
