From b1aba679d062e87073f3ad88937a749b41c5139f Mon Sep 17 00:00:00 2001 From: Vitaly Baranov Date: Wed, 23 Jan 2019 22:32:59 +0300 Subject: [PATCH] Class WriteBufferFromOwnString now can return StringRef too. --- dbms/src/IO/WriteBufferFromString.h | 3 +++ dbms/src/IO/WriteBufferFromVector.h | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/dbms/src/IO/WriteBufferFromString.h b/dbms/src/IO/WriteBufferFromString.h index 0611d284102..c833c7e3f52 100644 --- a/dbms/src/IO/WriteBufferFromString.h +++ b/dbms/src/IO/WriteBufferFromString.h @@ -2,6 +2,7 @@ #include #include +#include namespace DB @@ -29,6 +30,8 @@ class WriteBufferFromOwnString : public detail::StringHolder, public WriteBuffer public: WriteBufferFromOwnString() : WriteBufferFromString(value) {} + StringRef stringRef() const { return isFinished() ? StringRef(value) : StringRef(value.data(), pos - value.data()); } + std::string & str() { finish(); diff --git a/dbms/src/IO/WriteBufferFromVector.h b/dbms/src/IO/WriteBufferFromVector.h index 70e6ef5e36e..7cc7eaf25cb 100644 --- a/dbms/src/IO/WriteBufferFromVector.h +++ b/dbms/src/IO/WriteBufferFromVector.h @@ -64,6 +64,14 @@ public: set(nullptr, 0); } + bool isFinished() const { return is_finished; } + + void restart() + { + set(reinterpret_cast(vector.data()), vector.size()); + is_finished = false; + } + ~WriteBufferFromVector() override { if (!is_finished)