#pragma once #include #include #include #include #include #include namespace NYsonPull { namespace NDetail { namespace NInput { class TStreamBase: public NYsonPull::NInput::IStream { protected: result DoFillBufferFrom(IZeroCopyInput& input) { void* ptr = nullptr; size_t size = input.Next(&ptr); if (Y_UNLIKELY(size == 0)) { return result::at_end; } buffer().reset(static_cast(ptr), static_cast(ptr) + size); return result::have_more_data; } }; class TZeroCopy: public TStreamBase { IZeroCopyInput* Input; public: explicit TZeroCopy(IZeroCopyInput* input) : Input(input) { } protected: result do_fill_buffer() override { return DoFillBufferFrom(*Input); } }; template class TOwned: public TStreamBase { TBuffered Input; public: template explicit TOwned(Args&&... args) : Input(std::forward(args)...) { } protected: result do_fill_buffer() override { return DoFillBufferFrom(Input); } }; class TFHandle: public TOwned { public: TFHandle(int fd, size_t buffer_size) : TOwned(Duplicate(fd), buffer_size) { } }; } } // namespace NDetail }