diff options
author | arkady-e1ppa <arkady-e1ppa@yandex-team.com> | 2024-05-08 15:57:02 +0300 |
---|---|---|
committer | arkady-e1ppa <arkady-e1ppa@yandex-team.com> | 2024-05-08 16:07:56 +0300 |
commit | 1e4e9bda1dec7dbc595590b4c8f1beba4b7b80e2 (patch) | |
tree | f0d03324147511468252eed1499894a648ecf704 /yt | |
parent | 5f029c51f3ec2f729aad5cf3d24044f44187e085 (diff) | |
download | ydb-1e4e9bda1dec7dbc595590b4c8f1beba4b7b80e2.tar.gz |
Revert YT-21310: Introduce CYsonStructSource to remove code duplication in TYsonStruct implementation
Revert "YT-21310: Introduce CYsonStructSource to remove code duplication in TYsonStruct implementation"
This reverts commit b5dbf4de1df8156e23176662e15b167361fddb19, reversing
changes made to 5ab2a4add3801f5d310e76bf9ba496342d2b765a.
1f84c055d6e4df384230688c946a45dd6351a386
Diffstat (limited to 'yt')
-rw-r--r-- | yt/yt/core/ytree/yson_struct-inl.h | 24 | ||||
-rw-r--r-- | yt/yt/core/ytree/yson_struct.cpp | 6 | ||||
-rw-r--r-- | yt/yt/core/ytree/yson_struct.h | 31 | ||||
-rw-r--r-- | yt/yt/core/ytree/yson_struct_detail-inl.h | 426 | ||||
-rw-r--r-- | yt/yt/core/ytree/yson_struct_detail.h | 34 | ||||
-rw-r--r-- | yt/yt/core/ytree/yson_struct_enum.h | 21 | ||||
-rw-r--r-- | yt/yt/core/ytree/yson_struct_public.h | 48 |
7 files changed, 300 insertions, 290 deletions
diff --git a/yt/yt/core/ytree/yson_struct-inl.h b/yt/yt/core/ytree/yson_struct-inl.h index baa01de7b5..75f5b1db1d 100644 --- a/yt/yt/core/ytree/yson_struct-inl.h +++ b/yt/yt/core/ytree/yson_struct-inl.h @@ -264,7 +264,8 @@ TYsonStructRegistrar<TStruct>::operator TYsonStructRegistrar<TBase>() //////////////////////////////////////////////////////////////////////////////// -template <CExternallySerializable T> +template <class T> + requires CExternallySerializable<T> void Serialize(const T& value, NYson::IYsonConsumer* consumer) { using TSerializer = typename TGetExternalizedYsonStructTraits<T>::TExternalSerializer; @@ -272,13 +273,28 @@ void Serialize(const T& value, NYson::IYsonConsumer* consumer) Serialize(serializer, consumer); } -template <CExternallySerializable T, CYsonStructSource TSource> -void Deserialize(T& value, TSource source, bool postprocess, bool setDefaults) +template <class T> + requires CExternallySerializable<T> +void DeserializeExternalized(T& value, INodePtr node, bool postprocess, bool setDefaults) { using TTraits = TGetExternalizedYsonStructTraits<T>; using TSerializer = typename TTraits::TExternalSerializer; auto serializer = TSerializer::template CreateWritable<T, TSerializer>(value, setDefaults); - serializer.Load(std::move(source), postprocess, setDefaults); + serializer.Load(node, postprocess, setDefaults); +} + +template <class T> + requires CExternallySerializable<T> +void Deserialize(T& value, INodePtr node) +{ + DeserializeExternalized(value, std::move(node), /*postprocess*/ true, /*setDefaults*/ true); +} + +template <class T> + requires CExternallySerializable<T> +void Deserialize(T& value, NYson::TYsonPullParserCursor* cursor) +{ + Deserialize(value, NYson::ExtractTo<NYTree::INodePtr>(cursor)); } template <class T> diff --git a/yt/yt/core/ytree/yson_struct.cpp b/yt/yt/core/ytree/yson_struct.cpp index fbdad0be6b..b939d17b9a 100644 --- a/yt/yt/core/ytree/yson_struct.cpp +++ b/yt/yt/core/ytree/yson_struct.cpp @@ -51,16 +51,16 @@ void TYsonStructBase::Load( INodePtr node, bool postprocess, bool setDefaults, - const NYPath::TYPath& path) + const TYPath& path) { - Meta_->LoadStruct(this, std::move(node), postprocess, setDefaults, path); + Meta_->LoadStruct(this, node, postprocess, setDefaults, path); } void TYsonStructBase::Load( TYsonPullParserCursor* cursor, bool postprocess, bool setDefaults, - const NYPath::TYPath& path) + const TYPath& path) { Meta_->LoadStruct(this, cursor, postprocess, setDefaults, path); } diff --git a/yt/yt/core/ytree/yson_struct.h b/yt/yt/core/ytree/yson_struct.h index 5d384840a8..19300099bf 100644 --- a/yt/yt/core/ytree/yson_struct.h +++ b/yt/yt/core/ytree/yson_struct.h @@ -1,14 +1,13 @@ #pragma once #include "node.h" -#include "yson_struct_public.h" +#include "yson_struct_enum.h" #include <yt/yt/core/misc/error.h> #include <yt/yt/core/misc/mpl.h> #include <yt/yt/core/misc/property.h> #include <yt/yt/core/yson/public.h> - #include <yt/yt/library/syncmap/map.h> #include <library/cpp/yt/misc/enum.h> @@ -63,7 +62,7 @@ public: virtual ~TYsonStructBase() = default; void Load( - INodePtr node, + NYTree::INodePtr node, bool postprocess = true, bool setDefaults = true, const NYPath::TYPath& path = {}); @@ -294,6 +293,21 @@ private: //////////////////////////////////////////////////////////////////////////////// template <class T> +concept CExternalizedYsonStructTraits = requires { + typename T::TExternalSerializer; +}; + +template <class T> +concept CExternallySerializable = requires (T t) { + { GetExternalizedYsonStructTraits(t) } -> CExternalizedYsonStructTraits; +}; + +template <CExternallySerializable T> +using TGetExternalizedYsonStructTraits = decltype(GetExternalizedYsonStructTraits(std::declval<T>())); + +//////////////////////////////////////////////////////////////////////////////// + +template <class T> TIntrusivePtr<T> CloneYsonStruct(const TIntrusivePtr<const T>& obj); template <class T> TIntrusivePtr<T> CloneYsonStruct(const TIntrusivePtr<T>& obj); @@ -306,10 +320,15 @@ void Serialize(const TYsonStructBase& value, NYson::IYsonConsumer* consumer); void Deserialize(TYsonStructBase& value, INodePtr node); void Deserialize(TYsonStructBase& value, NYson::TYsonPullParserCursor* cursor); -template <CExternallySerializable T> +template <class T> + requires CExternallySerializable<T> void Serialize(const T& value, NYson::IYsonConsumer* consumer); -template <CExternallySerializable T, CYsonStructSource TSource> -void Deserialize(T& value, TSource source, bool postprocess = true, bool setDefaults = true); +template <class T> + requires CExternallySerializable<T> +void Deserialize(T& value, INodePtr node); +template <class T> + requires CExternallySerializable<T> +void Deserialize(T& value, NYson::TYsonPullParserCursor* cursor); template <class T> TIntrusivePtr<T> UpdateYsonStruct( diff --git a/yt/yt/core/ytree/yson_struct_detail-inl.h b/yt/yt/core/ytree/yson_struct_detail-inl.h index 3a0eefde3d..8c02116c43 100644 --- a/yt/yt/core/ytree/yson_struct_detail-inl.h +++ b/yt/yt/core/ytree/yson_struct_detail-inl.h @@ -35,228 +35,269 @@ concept SupportsDontSerializeDefault = //////////////////////////////////////////////////////////////////////////////// +// Primitive type template <class T> -T DeserializeMapKey(TStringBuf value) +void LoadFromNode( + T& parameter, + NYTree::INodePtr node, + const NYPath::TYPath& path, + std::optional<EUnrecognizedStrategy> /*recursiveUnrecognizedStrategy*/) { - if constexpr (TEnumTraits<T>::IsEnum) { - return ParseEnum<T>(value); - } else if constexpr (std::is_same_v<T, TGuid>) { - return TGuid::FromString(value); - } else if constexpr (TStrongTypedefTraits<T>::IsStrongTypedef) { - return T(DeserializeMapKey<typename TStrongTypedefTraits<T>::TUnderlying>(value)); - } else { - return FromString<T>(value); + try { + Deserialize(parameter, node); + } catch (const std::exception& ex) { + THROW_ERROR_EXCEPTION("Error reading parameter %v", path) + << ex; } } -//////////////////////////////////////////////////////////////////////////////// - -template <class T> -concept CNodePtr = requires (T node) { - [] (INodePtr) { } (node); -}; - -template <CNodePtr TNodePtr> -struct TYsonSourceTraits<TNodePtr> -{ - static constexpr bool IsValid = true; - - static INodePtr AsNode(TNodePtr& source) - { - // NRVO. - return source; - } - - static bool IsEmpty(TNodePtr& source) - { - return source->GetType() == ENodeType::Entity; - } - - static void Advance(TNodePtr& /*source*/) - { } - - template <class... TArgs, class TFiller> - static void FillVector(TNodePtr& source, std::vector<TArgs...>& vector, TFiller filler) - { - auto listNode = source->AsList(); - auto size = listNode->GetChildCount(); - vector.reserve(size); - for (int i = 0; i < size; ++i) { - filler(vector, std::move(listNode->GetChildOrThrow(i))); - } - } - - template <CAnyMap TMap, class TFiller> - static void FillMap(TNodePtr& source, TMap& map, TFiller filler) - { - auto mapNode = source->AsMap(); - - // NB: We iterate over temporary object anyway. - // Might as well move key/child into the filler - for (auto [key, child] : mapNode->GetChildren()) { - filler(map, std::move(key), std::move(child)); - } - } -}; - +// INodePtr template <> -struct TYsonSourceTraits<NYson::TYsonPullParserCursor*> +inline void LoadFromNode( + NYTree::INodePtr& parameter, + NYTree::INodePtr node, + const NYPath::TYPath& /*path*/, + std::optional<EUnrecognizedStrategy> /*recursiveUnrecognizedStrategy*/) { - static constexpr bool IsValid = true; - - static INodePtr AsNode(NYson::TYsonPullParserCursor*& source) - { - return NYson::ExtractTo<NYTree::INodePtr>(source); - } - - static bool IsEmpty(NYson::TYsonPullParserCursor*& source) - { - return (*source)->GetType() == NYson::EYsonItemType::EntityValue; - } - - static void Advance(NYson::TYsonPullParserCursor*& source) - { - source->Next(); + if (!parameter) { + parameter = node; + } else { + parameter = PatchNode(parameter, node); } +} - template <class... TArgs, class TFiller> - static void FillVector(NYson::TYsonPullParserCursor*& source, std::vector<TArgs...>& vector, TFiller filler) - { - source->ParseList([&](NYson::TYsonPullParserCursor* cursor) { - filler(vector, cursor); - }); +// TYsonStruct +template <CYsonStructDerived T> +void LoadFromNode( + TIntrusivePtr<T>& parameterValue, + NYTree::INodePtr node, + const NYPath::TYPath& path, + std::optional<EUnrecognizedStrategy> recursiveUnrecognizedStrategy) +{ + if (!parameterValue) { + parameterValue = New<T>(); } - template <CAnyMap TMap, class TFiller> - static void FillMap(NYson::TYsonPullParserCursor*& source, TMap& map, TFiller filler) - { - source->ParseMap([&] (NYson::TYsonPullParserCursor* cursor) { - auto key = ExtractTo<TString>(cursor); - filler(map, std::move(key), source); - }); + if (recursiveUnrecognizedStrategy) { + parameterValue->SetUnrecognizedStrategy(*recursiveUnrecognizedStrategy); } -}; -//////////////////////////////////////////////////////////////////////////////// + parameterValue->Load(node, /*postprocess*/ false, /*setDefaults*/ false, path); +} -// Primitive type -template <class T, CYsonStructSource TSource> -void LoadFromSource( +// YsonStructLite +template <std::derived_from<TYsonStructLite> T> +void LoadFromNode( T& parameter, - TSource source, + NYTree::INodePtr node, const NYPath::TYPath& path, - std::optional<EUnrecognizedStrategy> /*ignored*/) + std::optional<EUnrecognizedStrategy> /*recursiveUnrecognizedStrategy*/) { - using TTraits = TYsonSourceTraits<TSource>; - try { - Deserialize(parameter, TTraits::AsNode(source)); + parameter.Load(node, /*postprocess*/ false, /*setDefaults*/ false); } catch (const std::exception& ex) { THROW_ERROR_EXCEPTION("Error reading parameter %v", path) << ex; } } -// INodePtr -template <CYsonStructSource TSource> -void LoadFromSource( - INodePtr& parameter, - TSource source, +// ExternalizedYsonStruct +template <CExternallySerializable T> +void LoadFromNode( + T& parameter, + NYTree::INodePtr node, const NYPath::TYPath& path, - std::optional<EUnrecognizedStrategy> /*ignored*/) + std::optional<EUnrecognizedStrategy> /*recursiveUnrecognizedStrategy*/) { - using TTraits = TYsonSourceTraits<TSource>; - try { - auto node = TTraits::AsNode(source); - if (!parameter) { - parameter = std::move(node); - } else { - parameter = PatchNode(parameter, node); - } + DeserializeExternalized(parameter, node, /*postprocess*/ false, /*setDefaults*/ false); } catch (const std::exception& ex) { - THROW_ERROR_EXCEPTION("Error loading parameter %v", path) + THROW_ERROR_EXCEPTION("Error reading parameter %v", path) << ex; } } -// TYsonStruct -template <CYsonStructDerived T, CYsonStructSource TSource> -void LoadFromSource( - TIntrusivePtr<T>& parameter, - TSource source, +// std::optional +template <class T> +void LoadFromNode( + std::optional<T>& parameter, + NYTree::INodePtr node, const NYPath::TYPath& path, std::optional<EUnrecognizedStrategy> recursiveUnrecognizedStrategy) { - if (!parameter) { - parameter = New<T>(); + if (node->GetType() == NYTree::ENodeType::Entity) { + parameter = std::nullopt; + return; } - if (recursiveUnrecognizedStrategy) { - parameter->SetUnrecognizedStrategy(*recursiveUnrecognizedStrategy); + if (parameter.has_value()) { + LoadFromNode(*parameter, node, path, recursiveUnrecognizedStrategy); + } else { + T value; + LoadFromNode(value, node, path, recursiveUnrecognizedStrategy); + parameter = std::move(value); + } +} + +// std::vector +template <class... T> +void LoadFromNode( + std::vector<T...>& parameter, + NYTree::INodePtr node, + const NYPath::TYPath& path, + std::optional<EUnrecognizedStrategy> recursiveUnrecognizedStrategy) +{ + auto listNode = node->AsList(); + auto size = listNode->GetChildCount(); + parameter.clear(); + parameter.reserve(size); + for (int i = 0; i < size; ++i) { + LoadFromNode( + parameter.emplace_back(), + listNode->GetChildOrThrow(i), + path + "/" + NYPath::ToYPathLiteral(i), + recursiveUnrecognizedStrategy); } +} - parameter->Load(std::move(source), /*postprocess*/ false, /*setDefaults*/ false, path); +template <class T> +T DeserializeMapKey(TStringBuf value) +{ + if constexpr (TEnumTraits<T>::IsEnum) { + return ParseEnum<T>(value); + } else if constexpr (std::is_same_v<T, TGuid>) { + return TGuid::FromString(value); + } else if constexpr (TStrongTypedefTraits<T>::IsStrongTypedef) { + return T(DeserializeMapKey<typename TStrongTypedefTraits<T>::TUnderlying>(value)); + } else { + return FromString<T>(value); + } } -// YsonStructLite -template <std::derived_from<TYsonStructLite> T, CYsonStructSource TSource> -void LoadFromSource( - T& parameter, - TSource source, +// For any map. +template <template <typename...> class Map, class... T, class M = typename Map<T...>::mapped_type> +void LoadFromNode( + Map<T...>& parameter, + NYTree::INodePtr node, const NYPath::TYPath& path, - std::optional<EUnrecognizedStrategy> /*ignored*/) + std::optional<EUnrecognizedStrategy> recursiveUnrecognizedStrategy) { - try { - parameter.Load(std::move(source), /*postprocess*/ false, /*setDefaults*/ false, path); - } catch (const std::exception& ex) { - THROW_ERROR_EXCEPTION("Error reading parameter %v", path) - << ex; + auto mapNode = node->AsMap(); + for (const auto& [key, child] : mapNode->GetChildren()) { + M value; + LoadFromNode( + value, + child, + path + "/" + NYPath::ToYPathLiteral(key), + recursiveUnrecognizedStrategy); + parameter[DeserializeMapKey<typename Map<T...>::key_type>(key)] = std::move(value); } } -// ExternalizedYsonStruct -template <CExternallySerializable T, CYsonStructSource TSource> -void LoadFromSource( +//////////////////////////////////////////////////////////////////////////////// + +// Primitive type or YsonStructLite +// See LoadFromNode for further specialization. +template <class T> +void LoadFromCursor( T& parameter, - TSource source, + NYson::TYsonPullParserCursor* cursor, const NYPath::TYPath& path, - std::optional<EUnrecognizedStrategy> /*ignored*/) + std::optional<EUnrecognizedStrategy> recursiveUnrecognizedStrategy) +{ + LoadFromNode(parameter, NYson::ExtractTo<NYTree::INodePtr>(cursor), path, recursiveUnrecognizedStrategy); +} + +//////////////////////////////////////////////////////////////////////////////// + +template <CYsonStructDerived T> +void LoadFromCursor( + TIntrusivePtr<T>& parameterValue, + NYson::TYsonPullParserCursor* cursor, + const NYPath::TYPath& path, + std::optional<EUnrecognizedStrategy> recursiveUnrecognizedStrategy); + +template <class... T> +void LoadFromCursor( + std::vector<T...>& parameter, + NYson::TYsonPullParserCursor* cursor, + const NYPath::TYPath& path, + std::optional<EUnrecognizedStrategy> recursiveUnrecognizedStrategy); + +// std::optional +template <class T> +void LoadFromCursor( + std::optional<T>& parameter, + NYson::TYsonPullParserCursor* cursor, + const NYPath::TYPath& path, + std::optional<EUnrecognizedStrategy> recursiveUnrecognizedStrategy); + +template <template <typename...> class Map, class... T, class M = typename Map<T...>::mapped_type> +void LoadFromCursor( + Map<T...>& parameter, + NYson::TYsonPullParserCursor* cursor, + const NYPath::TYPath& path, + std::optional<EUnrecognizedStrategy> recursiveUnrecognizedStrategy); + +//////////////////////////////////////////////////////////////////////////////// + +// INodePtr +template <> +inline void LoadFromCursor( + NYTree::INodePtr& parameter, + NYson::TYsonPullParserCursor* cursor, + const NYPath::TYPath& path, + std::optional<EUnrecognizedStrategy> recursiveUnrecognizedStrategy) { try { - Deserialize(parameter, std::move(source), /*postprocess*/ false, /*setDefaults*/ false); + auto node = NYson::ExtractTo<INodePtr>(cursor); + LoadFromNode(parameter, std::move(node), path, recursiveUnrecognizedStrategy); } catch (const std::exception& ex) { - THROW_ERROR_EXCEPTION("Error reading parameter %v", path) + THROW_ERROR_EXCEPTION("Error loading parameter %v", path) << ex; } } +// TYsonStruct +template <CYsonStructDerived T> +void LoadFromCursor( + TIntrusivePtr<T>& parameterValue, + NYson::TYsonPullParserCursor* cursor, + const NYPath::TYPath& path, + std::optional<EUnrecognizedStrategy> recursiveUnrecognizedStrategy) +{ + if (!parameterValue) { + parameterValue = New<T>(); + } + + if (recursiveUnrecognizedStrategy) { + parameterValue->SetUnrecognizedStrategy(*recursiveUnrecognizedStrategy); + } + + parameterValue->Load(cursor, /*postprocess*/ false, /*setDefaults*/ false, path); +} + // std::optional -template <class T, CYsonStructSource TSource> -void LoadFromSource( +template <class T> +void LoadFromCursor( std::optional<T>& parameter, - TSource source, + NYson::TYsonPullParserCursor* cursor, const NYPath::TYPath& path, std::optional<EUnrecognizedStrategy> recursiveUnrecognizedStrategy) { - using TTraits = TYsonSourceTraits<TSource>; - try { - if (TTraits::IsEmpty(source)) { + if ((*cursor)->GetType() == NYson::EYsonItemType::EntityValue) { parameter = std::nullopt; - TTraits::Advance(source); - return; - } - - if (parameter.has_value()) { - LoadFromSource(*parameter, std::move(source), path, recursiveUnrecognizedStrategy); - return; + cursor->Next(); + } else { + if (parameter.has_value()) { + LoadFromCursor(*parameter, cursor, path, recursiveUnrecognizedStrategy); + } else { + T value; + LoadFromCursor(value, cursor, path, recursiveUnrecognizedStrategy); + parameter = std::move(value); + } } - - T value; - LoadFromSource(value, std::move(source), path, recursiveUnrecognizedStrategy); - parameter = std::move(value); - } catch (const std::exception& ex) { THROW_ERROR_EXCEPTION("Error loading parameter %v", path) << ex; @@ -264,23 +305,20 @@ void LoadFromSource( } // std::vector -template <CStdVector TVector, CYsonStructSource TSource> -void LoadFromSource( - TVector& parameter, - TSource source, +template <class... T> +void LoadFromCursor( + std::vector<T...>& parameter, + NYson::TYsonPullParserCursor* cursor, const NYPath::TYPath& path, std::optional<EUnrecognizedStrategy> recursiveUnrecognizedStrategy) { - using TTraits = TYsonSourceTraits<TSource>; - try { parameter.clear(); int index = 0; - - TTraits::FillVector(source, parameter, [&] (auto& vector, auto elementSource) { - LoadFromSource( - vector.emplace_back(), - elementSource, + cursor->ParseList([&] (NYson::TYsonPullParserCursor* cursor) { + LoadFromCursor( + parameter.emplace_back(), + cursor, path + "/" + NYPath::ToYPathLiteral(index), recursiveUnrecognizedStrategy); ++index; @@ -291,28 +329,24 @@ void LoadFromSource( } } -// any map. -template <CAnyMap TMap, CYsonStructSource TSource> -void LoadFromSource( - TMap& parameter, - TSource source, +// For any map. +template <template <typename...> class Map, class... T, class M> +void LoadFromCursor( + Map<T...>& parameter, + NYson::TYsonPullParserCursor* cursor, const NYPath::TYPath& path, std::optional<EUnrecognizedStrategy> recursiveUnrecognizedStrategy) { - using TTraits = TYsonSourceTraits<TSource>; - // TODO(arkady-e1ppa): Remove "typename" when clang-14 is abolished. - using TKey = typename TMap::key_type; - using TValue = typename TMap::mapped_type; - try { - TTraits::FillMap(source, parameter, [&] (TMap& map, const TString& key, auto childSource) { - TValue value; - LoadFromSource( + cursor->ParseMap([&] (NYson::TYsonPullParserCursor* cursor) { + auto key = ExtractTo<TString>(cursor); + M value; + LoadFromCursor( value, - childSource, + cursor, path + "/" + NYPath::ToYPathLiteral(key), recursiveUnrecognizedStrategy); - map[DeserializeMapKey<TKey>(key)] = std::move(value); + parameter[DeserializeMapKey<typename Map<T...>::key_type>(key)] = std::move(value); }); } catch (const std::exception& ex) { THROW_ERROR_EXCEPTION("Error loading parameter %v", path) @@ -406,9 +440,9 @@ inline void PostprocessRecursive( } // std::vector -template <CStdVector TVector> +template <class T> inline void PostprocessRecursive( - TVector& parameter, + std::vector<T>& parameter, const NYPath::TYPath& path) { for (size_t i = 0; i < parameter.size(); ++i) { @@ -419,9 +453,9 @@ inline void PostprocessRecursive( } // any map -template <CAnyMap TMap> +template <template <typename...> class Map, class... T, class M = typename Map<T...>::mapped_type> inline void PostprocessRecursive( - TMap& parameter, + Map<T...>& parameter, const NYPath::TYPath& path) { for (auto& [key, value] : parameter) { @@ -469,15 +503,15 @@ inline void ResetOnLoad(std::optional<T>& parameter) } // std::vector -template <CStdVector TVector> -inline void ResetOnLoad(TVector& parameter) +template <class T> +inline void ResetOnLoad(std::vector<T>& parameter) { parameter.clear(); } // any map -template <CAnyMap TMap> -inline void ResetOnLoad(TMap& parameter) +template <template <typename...> class Map, class... T, class M = typename Map<T...>::mapped_type> +inline void ResetOnLoad(Map<T...>& parameter) { parameter.clear(); } @@ -530,7 +564,7 @@ void TYsonStructParameter<TValue>::Load( if (ResetOnLoad_) { NPrivate::ResetOnLoad(FieldAccessor_->GetValue(self)); } - NPrivate::LoadFromSource( + NPrivate::LoadFromNode( FieldAccessor_->GetValue(self), std::move(node), options.Path, @@ -551,7 +585,7 @@ void TYsonStructParameter<TValue>::Load( if (ResetOnLoad_) { NPrivate::ResetOnLoad(FieldAccessor_->GetValue(self)); } - NPrivate::LoadFromSource( + NPrivate::LoadFromCursor( FieldAccessor_->GetValue(self), cursor, options.Path, @@ -573,7 +607,7 @@ void TYsonStructParameter<TValue>::SafeLoad( TValue oldValue = FieldAccessor_->GetValue(self); try { FieldAccessor_->GetValue(self) = TValue(); - NPrivate::LoadFromSource( + NPrivate::LoadFromNode( FieldAccessor_->GetValue(self), node, options.Path, diff --git a/yt/yt/core/ytree/yson_struct_detail.h b/yt/yt/core/ytree/yson_struct_detail.h index 91700f89e7..17da9bf149 100644 --- a/yt/yt/core/ytree/yson_struct_detail.h +++ b/yt/yt/core/ytree/yson_struct_detail.h @@ -1,6 +1,6 @@ #pragma once -#include "yson_struct_public.h" +#include "yson_struct_enum.h" #include <yt/yt/core/yson/public.h> #include <yt/yt/core/ypath/public.h> @@ -12,38 +12,6 @@ namespace NYT::NYTree { //////////////////////////////////////////////////////////////////////////////// -namespace NPrivate { - -// Least common denominator between INodePtr -// and TYsonPullParserCursor. -// Maybe something else in the future. -template <class T> -struct TYsonSourceTraits -{ - static constexpr bool IsValid = false; - - static INodePtr AsNode(T& source) - requires false; - - static bool IsEmpty(T& source) - requires false; - - static void Advance(T& source) - requires false; - - template <CStdVector TVector, class TFiller> - static void FillVector(T& source, TVector& vector, TFiller filler) - requires false; - - template <CAnyMap TMap, class TFiller> - static void FillMap(T& source, TMap& map, TFiller filler) - requires false; -}; - -} // namespace NPrivate - -//////////////////////////////////////////////////////////////////////////////// - template <class TStruct, class TValue> using TYsonStructField = TValue(TStruct::*); diff --git a/yt/yt/core/ytree/yson_struct_enum.h b/yt/yt/core/ytree/yson_struct_enum.h new file mode 100644 index 0000000000..a35fba6d0d --- /dev/null +++ b/yt/yt/core/ytree/yson_struct_enum.h @@ -0,0 +1,21 @@ +#pragma once + +#include <library/cpp/yt/memory/serialize.h> + +#include <library/cpp/yt/misc/enum.h> + +namespace NYT::NYTree { + +/////////////////////////////////////////////////////////////////////////////// + +DEFINE_ENUM(EUnrecognizedStrategy, + (Drop) + (Keep) + (KeepRecursive) + (Throw) + (ThrowRecursive) +); + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT::NYTree diff --git a/yt/yt/core/ytree/yson_struct_public.h b/yt/yt/core/ytree/yson_struct_public.h deleted file mode 100644 index 495a47b46f..0000000000 --- a/yt/yt/core/ytree/yson_struct_public.h +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include <library/cpp/yt/memory/serialize.h> - -#include <library/cpp/yt/misc/enum.h> - -namespace NYT::NYTree { - -/////////////////////////////////////////////////////////////////////////////// - -DEFINE_ENUM(EUnrecognizedStrategy, - (Drop) - (Keep) - (KeepRecursive) - (Throw) - (ThrowRecursive) -); - -//////////////////////////////////////////////////////////////////////////////// - -template <class T> -concept CExternalizedYsonStructTraits = requires { - typename T::TExternalSerializer; -}; - -template <class T> -concept CExternallySerializable = requires (T t) { - { GetExternalizedYsonStructTraits(t) } -> CExternalizedYsonStructTraits; -}; - -template <CExternallySerializable T> -using TGetExternalizedYsonStructTraits = decltype(GetExternalizedYsonStructTraits(std::declval<T>())); - -//////////////////////////////////////////////////////////////////////////////// - -namespace NPrivate { - -template <class T> -struct TYsonSourceTraits; - -} // namespace NPrivate - -template <class T> -concept CYsonStructSource = NPrivate::TYsonSourceTraits<T>::IsValid; - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT::NYTree |