zerocopy_output_writer.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include <util/stream/zerocopy_output.h>
  3. namespace NSkiff {
  4. ////////////////////////////////////////////////////////////////////////////////
  5. // Simple wrapper around
  6. class TZeroCopyOutputStreamWriter
  7. : private TNonCopyable
  8. {
  9. public:
  10. explicit TZeroCopyOutputStreamWriter(IZeroCopyOutput* output);
  11. ~TZeroCopyOutputStreamWriter();
  12. Y_FORCE_INLINE char* Current() const;
  13. Y_FORCE_INLINE ui64 RemainingBytes() const;
  14. Y_FORCE_INLINE void Advance(size_t bytes);
  15. void UndoRemaining();
  16. Y_FORCE_INLINE void Write(const void* buffer, size_t length);
  17. Y_FORCE_INLINE ui64 GetTotalWrittenSize() const;
  18. private:
  19. void ObtainNextBlock();
  20. private:
  21. IZeroCopyOutput* Output_;
  22. char* Current_ = nullptr;
  23. ui64 RemainingBytes_ = 0;
  24. ui64 TotalWrittenBlockSize_ = 0;
  25. };
  26. ////////////////////////////////////////////////////////////////////////////////
  27. } // namespace NSkiff
  28. #define ZEROCOPY_OUTPUT_WRITER_INL_H_
  29. #include "zerocopy_output_writer-inl.h"
  30. #undef ZEROCOPY_OUTPUT_WRITER_INL_H_