|
1 | 1 | #include "size.h" |
2 | 2 |
|
3 | 3 | #include <yt/yt/core/misc/error.h> |
| 4 | +#include <yt/yt/core/ytree/convert.h> |
4 | 5 |
|
5 | 6 | #include <util/string/cast.h> |
6 | 7 |
|
@@ -67,6 +68,44 @@ TSize TSize::FromString(TStringBuf serializedValue) |
67 | 68 |
|
68 | 69 | //////////////////////////////////////////////////////////////////////////////// |
69 | 70 |
|
| 71 | +void Serialize(const TSize& value, NYson::IYsonConsumer* consumer) |
| 72 | +{ |
| 73 | + Serialize(value.Underlying(), consumer); |
| 74 | +} |
| 75 | + |
| 76 | +void Deserialize(TSize& value, INodePtr node) |
| 77 | +{ |
| 78 | + if (node->GetType() == ENodeType::Int64) { |
| 79 | + value = TSize(node->AsInt64()->GetValue()); |
| 80 | + } else if (node->GetType() == ENodeType::Uint64) { |
| 81 | + value = TSize(CheckedIntegralCast<i64>(node->AsUint64()->GetValue())); |
| 82 | + } else if (node->GetType() == ENodeType::String) { |
| 83 | + value = TSize::FromString(node->AsString()->GetValue()); |
| 84 | + } else { |
| 85 | + THROW_ERROR_EXCEPTION("Cannot parse TSize value from %Qlv", |
| 86 | + node->GetType()); |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +void Deserialize(TSize& value, NYson::TYsonPullParserCursor* cursor) |
| 91 | +{ |
| 92 | + if ((*cursor)->GetType() == NYson::EYsonItemType::Int64Value) { |
| 93 | + value = TSize((*cursor)->UncheckedAsInt64()); |
| 94 | + cursor->Next(); |
| 95 | + } else if ((*cursor)->GetType() == NYson::EYsonItemType::Uint64Value) { |
| 96 | + value = TSize(CheckedIntegralCast<i64>((*cursor)->UncheckedAsUint64())); |
| 97 | + cursor->Next(); |
| 98 | + } else if ((*cursor)->GetType() == NYson::EYsonItemType::StringValue) { |
| 99 | + value = TSize::FromString((*cursor)->UncheckedAsString()); |
| 100 | + cursor->Next(); |
| 101 | + } else { |
| 102 | + THROW_ERROR_EXCEPTION("Cannot parse TSize value from %Qlv", |
| 103 | + (*cursor)->GetType()); |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +//////////////////////////////////////////////////////////////////////////////// |
| 108 | + |
70 | 109 | } // namespace NYT::NYTree |
71 | 110 |
|
72 | 111 | //////////////////////////////////////////////////////////////////////////////// |
|
0 commit comments