zerocopy_output_writer.cpp 879 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "zerocopy_output_writer.h"
  2. namespace NSkiff {
  3. ////////////////////////////////////////////////////////////////////////////////
  4. TZeroCopyOutputStreamWriter::TZeroCopyOutputStreamWriter(IZeroCopyOutput* output)
  5. : Output_(output)
  6. {
  7. ObtainNextBlock();
  8. }
  9. TZeroCopyOutputStreamWriter::~TZeroCopyOutputStreamWriter()
  10. {
  11. if (RemainingBytes_ > 0) {
  12. UndoRemaining();
  13. }
  14. }
  15. void TZeroCopyOutputStreamWriter::ObtainNextBlock()
  16. {
  17. if (RemainingBytes_ > 0) {
  18. UndoRemaining();
  19. }
  20. RemainingBytes_ = Output_->Next(&Current_);
  21. TotalWrittenBlockSize_ += RemainingBytes_;
  22. }
  23. void TZeroCopyOutputStreamWriter::UndoRemaining()
  24. {
  25. Output_->Undo(RemainingBytes_);
  26. TotalWrittenBlockSize_ -= RemainingBytes_;
  27. RemainingBytes_ = 0;
  28. }
  29. ////////////////////////////////////////////////////////////////////////////////
  30. } // namespace NSkiff