#pragma once #include #include #include #include #include namespace NYql { class TChunkedBuffer { public: TChunkedBuffer() = default; TChunkedBuffer(const TChunkedBuffer&) = default; TChunkedBuffer(TChunkedBuffer&& other); TChunkedBuffer& operator=(TChunkedBuffer&& other); explicit TChunkedBuffer(TStringBuf buf, const std::shared_ptr& owner); explicit TChunkedBuffer(TString&& str); [[nodiscard]] inline size_t ContigousSize() const { return Items_.empty() ? 0 : Front().Buf.size(); } [[nodiscard]] inline size_t Size() const { return Size_; } [[nodiscard]] inline bool Empty() const { return Size_ == 0; } struct TChunk { TStringBuf Buf; std::shared_ptr Owner; }; [[nodiscard]] const TChunk& Front() const; size_t CopyTo(IOutputStream& dst, size_t toCopy = std::numeric_limits::max()) const; TChunkedBuffer& Append(TStringBuf buf, const std::shared_ptr& owner); TChunkedBuffer& Append(TString&& str); TChunkedBuffer& Append(TChunkedBuffer&& other); TChunkedBuffer& Clear(); TChunkedBuffer& Erase(size_t size); private: std::deque Items_; size_t Size_ = 0; }; class TChunkedBufferOutput: public IOutputStream { public: explicit TChunkedBufferOutput(TChunkedBuffer& dst); private: void DoWrite(const void* buf, size_t len) override; TChunkedBuffer& Dst_; }; TChunkedBuffer CopyData(const TChunkedBuffer& src); TChunkedBuffer CopyData(TChunkedBuffer&& src); } // namespace NYql