zerocopy_output_writer-inl.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #ifndef ZEROCOPY_OUTPUT_WRITER_INL_H_
  3. #error "Direct inclusion of this file is not allowed, include zerocopy_output_writer.h"
  4. // For the sake of sane code completion.
  5. #include "zerocopy_output_writer.h"
  6. #endif
  7. #include <util/system/yassert.h>
  8. namespace NSkiff {
  9. ////////////////////////////////////////////////////////////////////////////////
  10. char* TZeroCopyOutputStreamWriter::Current() const
  11. {
  12. return Current_;
  13. }
  14. ui64 TZeroCopyOutputStreamWriter::RemainingBytes() const
  15. {
  16. return RemainingBytes_;
  17. }
  18. void TZeroCopyOutputStreamWriter::Advance(size_t bytes)
  19. {
  20. Y_ABORT_UNLESS(bytes <= RemainingBytes_);
  21. Current_ += bytes;
  22. RemainingBytes_ -= bytes;
  23. }
  24. void TZeroCopyOutputStreamWriter::Write(const void* buffer, size_t length)
  25. {
  26. if (length > RemainingBytes_) {
  27. UndoRemaining();
  28. Output_->Write(buffer, length);
  29. TotalWrittenBlockSize_ += length;
  30. ObtainNextBlock();
  31. } else {
  32. memcpy(Current_, buffer, length);
  33. Advance(length);
  34. }
  35. }
  36. ui64 TZeroCopyOutputStreamWriter::GetTotalWrittenSize() const
  37. {
  38. return TotalWrittenBlockSize_ - RemainingBytes_;
  39. }
  40. ////////////////////////////////////////////////////////////////////////////////
  41. } // namespace NSkiff