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.cpp | |
| 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.cpp')
| -rw-r--r-- | yt/cpp/mapreduce/interface/serialize.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/yt/cpp/mapreduce/interface/serialize.cpp b/yt/cpp/mapreduce/interface/serialize.cpp index 28a734a500b..869b39addb4 100644 --- a/yt/cpp/mapreduce/interface/serialize.cpp +++ b/yt/cpp/mapreduce/interface/serialize.cpp @@ -572,6 +572,40 @@ void Deserialize(TTabletInfo& value, const TNode& node) DESERIALIZE_ITEM("barrier_timestamp", value.BarrierTimestamp) } +void Deserialize(TDuration& value, const TNode& node) +{ + switch (node.GetType()) { + case TNode::EType::Int64: { + auto ms = node.AsInt64(); + if (ms < 0) { + ythrow yexception() << "Duration cannot be negative"; + } + value = TDuration::MilliSeconds(static_cast<ui64>(ms)); + break; + } + + case TNode::EType::Uint64: + value = TDuration::MilliSeconds(node.AsUint64()); + break; + + case TNode::EType::Double: { + auto ms = node.AsDouble(); + if (ms < 0) { + ythrow yexception() << "Duration cannot be negative"; + } + value = TDuration::MicroSeconds(static_cast<ui64>(ms * 1'000.0)); + break; + } + + case TNode::EType::String: + value = TDuration::Parse(node.AsString()); + break; + + default: + ythrow yexception() << "Cannot parse duration from " << node.GetType(); + } +} + void Serialize(const NTi::TTypePtr& type, NYson::IYsonConsumer* consumer) { auto yson = NTi::NIo::SerializeYson(type.Get()); |
