summaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/memory
diff options
context:
space:
mode:
authoryurial <[email protected]>2023-11-16 13:59:02 +0300
committeryurial <[email protected]>2023-11-16 14:43:37 +0300
commita2fd00a24fcb20211418b797cb6191c4f1afa6ea (patch)
tree68e33195baef03090a66c0e3868c89bfd2268480 /library/cpp/yt/memory
parentcab414f768af417824e8def2b045b5f13c5e7931 (diff)
Support Save/Load TYsonString
Diffstat (limited to 'library/cpp/yt/memory')
-rw-r--r--library/cpp/yt/memory/ref.h4
-rw-r--r--library/cpp/yt/memory/shared_range.h2
-rw-r--r--library/cpp/yt/memory/unittests/ref_ut.cpp22
-rw-r--r--library/cpp/yt/memory/unittests/ya.make1
4 files changed, 29 insertions, 0 deletions
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<T>& parts);
#define REF_INL_H_
#include "ref-inl.h"
#undef REF_INL_H_
+
+//! Serialize TSharedRef like vector<char>. Useful for ::Save, ::Load serialization/deserialization. See util/ysaveload.h.
+template <>
+class TSerializer<NYT::TSharedRef>: public TVectorSerializer<NYT::TSharedRange<char>> {};
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 <library/cpp/yt/assert/assert.h>
+#include <util/ysaveload.h>
+
#include <optional>
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 <library/cpp/testing/gtest/gtest.h>
+
+#include <library/cpp/testing/gtest_extensions/assertions.h>
+
+#include <library/cpp/yt/memory/ref.h>
+
+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)