From a2fd00a24fcb20211418b797cb6191c4f1afa6ea Mon Sep 17 00:00:00 2001 From: yurial Date: Thu, 16 Nov 2023 13:59:02 +0300 Subject: Support Save/Load TYsonString --- library/cpp/yt/memory/ref.h | 4 ++++ library/cpp/yt/memory/shared_range.h | 2 ++ library/cpp/yt/memory/unittests/ref_ut.cpp | 22 ++++++++++++++++++++++ library/cpp/yt/memory/unittests/ya.make | 1 + 4 files changed, 29 insertions(+) create mode 100644 library/cpp/yt/memory/unittests/ref_ut.cpp (limited to 'library/cpp/yt/memory') diff --git a/library/cpp/yt/memory/ref.h b/library/cpp/yt/memory/ref.h index 2b2a0792ab5..2177778a8f3 100644 --- a/library/cpp/yt/memory/ref.h +++ b/library/cpp/yt/memory/ref.h @@ -403,3 +403,7 @@ size_t GetByteSize(const std::vector& parts); #define REF_INL_H_ #include "ref-inl.h" #undef REF_INL_H_ + +//! Serialize TSharedRef like vector. Useful for ::Save, ::Load serialization/deserialization. See util/ysaveload.h. +template <> +class TSerializer: public TVectorSerializer> {}; diff --git a/library/cpp/yt/memory/shared_range.h b/library/cpp/yt/memory/shared_range.h index e1c262f418f..de5fc354eaa 100644 --- a/library/cpp/yt/memory/shared_range.h +++ b/library/cpp/yt/memory/shared_range.h @@ -7,6 +7,8 @@ #include +#include + #include namespace NYT { diff --git a/library/cpp/yt/memory/unittests/ref_ut.cpp b/library/cpp/yt/memory/unittests/ref_ut.cpp new file mode 100644 index 00000000000..8ecd57e15d2 --- /dev/null +++ b/library/cpp/yt/memory/unittests/ref_ut.cpp @@ -0,0 +1,22 @@ +#include + +#include + +#include + +namespace NYT::NYson { +namespace { + +//////////////////////////////////////////////////////////////////////////////// + +TEST(TSharedRefTest, Save) +{ + const TSharedRef expected = TSharedRef::FromString("My tests data"); + TStringStream s; + ::Save(&s, expected); // only Save supported for TSharedRef. You can ::Load serialized data to vector. +} + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace +} // namespace NYT::NYson diff --git a/library/cpp/yt/memory/unittests/ya.make b/library/cpp/yt/memory/unittests/ya.make index 514caa93a3b..3658eefce1f 100644 --- a/library/cpp/yt/memory/unittests/ya.make +++ b/library/cpp/yt/memory/unittests/ya.make @@ -15,6 +15,7 @@ SRCS( intrusive_ptr_ut.cpp shared_range_ut.cpp weak_ptr_ut.cpp + ref_ut.cpp ) IF (NOT OS_WINDOWS) -- cgit v1.3