summaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/interface/serialize.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'yt/cpp/mapreduce/interface/serialize.cpp')
-rw-r--r--yt/cpp/mapreduce/interface/serialize.cpp34
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());