aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.com>2022-09-15 10:16:02 +0300
committerbabenko <babenko@yandex-team.com>2022-09-15 10:16:02 +0300
commitb9588379f518a95feabccf562b290a487f8f130a (patch)
treea0e9303aaaa0ec7fb9d983c884ccb4d5b9f4c327 /library/cpp
parent83f3ea3ed2808ba1449a8af8aa3f72f29bc80efa (diff)
downloadydb-b9588379f518a95feabccf562b290a487f8f130a.tar.gz
Support logging unstructured messages to structured log
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/yt/memory/ref-inl.h10
-rw-r--r--library/cpp/yt/memory/ref.h6
-rw-r--r--library/cpp/yt/yson_string/string.cpp17
-rw-r--r--library/cpp/yt/yson_string/string.h4
4 files changed, 36 insertions, 1 deletions
diff --git a/library/cpp/yt/memory/ref-inl.h b/library/cpp/yt/memory/ref-inl.h
index 2d9a174e02..6f2104962c 100644
--- a/library/cpp/yt/memory/ref-inl.h
+++ b/library/cpp/yt/memory/ref-inl.h
@@ -47,6 +47,11 @@ Y_FORCE_INLINE TRef TRef::FromPod(const T& data)
return TRef(&data, sizeof (data));
}
+Y_FORCE_INLINE TStringBuf TRef::ToStringBuf() const
+{
+ return TStringBuf(Begin(), Size());
+}
+
Y_FORCE_INLINE TRef TRef::Slice(size_t startOffset, size_t endOffset) const
{
YT_ASSERT(endOffset >= startOffset && endOffset <= Size());
@@ -127,6 +132,11 @@ Y_FORCE_INLINE TSharedRef TSharedRef::FromString(TString str)
return FromString<TDefaultSharedBlobTag>(std::move(str));
}
+Y_FORCE_INLINE TStringBuf TSharedRef::ToStringBuf() const
+{
+ return TStringBuf(Begin(), Size());
+}
+
template <class TTag>
Y_FORCE_INLINE TSharedRef TSharedRef::MakeCopy(TRef ref)
{
diff --git a/library/cpp/yt/memory/ref.h b/library/cpp/yt/memory/ref.h
index cc7942176c..f93dc6dcfa 100644
--- a/library/cpp/yt/memory/ref.h
+++ b/library/cpp/yt/memory/ref.h
@@ -43,6 +43,9 @@ public:
template <class T>
static TRef FromPod(const T& data);
+ //! Converts to TStringBuf.
+ TStringBuf ToStringBuf() const;
+
//! Creates a TRef for a part of existing range.
TRef Slice(size_t startOffset, size_t endOffset) const;
@@ -142,6 +145,9 @@ public:
//! Creates a TSharedRef for a given blob taking ownership of its content.
static TSharedRef FromBlob(TBlob&& blob);
+ //! Converts to TStringBuf.
+ TStringBuf ToStringBuf() const;
+
//! Creates a copy of a given TRef.
//! The memory is marked with a given tag.
static TSharedRef MakeCopy(TRef ref, TRefCountedTypeCookie tagCookie);
diff --git a/library/cpp/yt/yson_string/string.cpp b/library/cpp/yt/yson_string/string.cpp
index 99d45e8616..15eafdf615 100644
--- a/library/cpp/yt/yson_string/string.cpp
+++ b/library/cpp/yt/yson_string/string.cpp
@@ -155,7 +155,7 @@ TString TYsonString::ToString() const
[] (const TNullPayload&) -> TString {
YT_ABORT();
},
- [&] (const TRefCountedPtr&) {
+ [&] (const THolder&) {
return TString(AsStringBuf());
},
[] (const TString& payload) {
@@ -163,6 +163,21 @@ TString TYsonString::ToString() const
});
}
+TSharedRef TYsonString::ToSharedRef() const
+{
+ return Visit(
+ Payload_,
+ [] (const TNullPayload&) -> TSharedRef {
+ YT_ABORT();
+ },
+ [&] (const THolder& holder) {
+ return TSharedRef(Begin_, Size_, holder);
+ },
+ [] (const TString& payload) {
+ return TSharedRef::FromString(payload);
+ });
+}
+
size_t TYsonString::ComputeHash() const
{
return THash<TStringBuf>()(TStringBuf(Begin_, Begin_ + Size_));
diff --git a/library/cpp/yt/yson_string/string.h b/library/cpp/yt/yson_string/string.h
index e13af37a6d..8feb01806d 100644
--- a/library/cpp/yt/yson_string/string.h
+++ b/library/cpp/yt/yson_string/string.h
@@ -100,6 +100,10 @@ public:
//! Copies the data in case the payload is not TString.
TString ToString() const;
+ //! Returns the data represented by TSharedRef. The instance must be non-null.
+ //! The data is never copied.
+ TSharedRef ToSharedRef() const;
+
//! Computes the hash code.
size_t ComputeHash() const;