diff options
author | qrort <qrort@yandex-team.com> | 2022-11-30 23:47:12 +0300 |
---|---|---|
committer | qrort <qrort@yandex-team.com> | 2022-11-30 23:47:12 +0300 |
commit | 22f8ae0e3f5d68b92aecccdf96c1d841a0334311 (patch) | |
tree | bffa27765faf54126ad44bcafa89fadecb7a73d7 /library/cpp/skiff/zerocopy_output_writer-inl.h | |
parent | 332b99e2173f0425444abb759eebcb2fafaa9209 (diff) | |
download | ydb-22f8ae0e3f5d68b92aecccdf96c1d841a0334311.tar.gz |
validate canons without yatest_common
Diffstat (limited to 'library/cpp/skiff/zerocopy_output_writer-inl.h')
-rw-r--r-- | library/cpp/skiff/zerocopy_output_writer-inl.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/library/cpp/skiff/zerocopy_output_writer-inl.h b/library/cpp/skiff/zerocopy_output_writer-inl.h new file mode 100644 index 0000000000..6bd067c9fa --- /dev/null +++ b/library/cpp/skiff/zerocopy_output_writer-inl.h @@ -0,0 +1,51 @@ +#pragma once +#ifndef ZEROCOPY_OUTPUT_WRITER_INL_H_ +#error "Direct inclusion of this file is not allowed, include zerocopy_output_writer.h" +// For the sake of sane code completion. +#include "zerocopy_output_writer.h" +#endif + +#include <util/system/yassert.h> + +namespace NSkiff { + +//////////////////////////////////////////////////////////////////////////////// + +char* TZeroCopyOutputStreamWriter::Current() const +{ + return Current_; +} + +ui64 TZeroCopyOutputStreamWriter::RemainingBytes() const +{ + return RemainingBytes_; +} + +void TZeroCopyOutputStreamWriter::Advance(size_t bytes) +{ + Y_VERIFY(bytes <= RemainingBytes_); + Current_ += bytes; + RemainingBytes_ -= bytes; +} + +void TZeroCopyOutputStreamWriter::Write(const void* buffer, size_t length) +{ + if (length > RemainingBytes_) { + UndoRemaining(); + Output_->Write(buffer, length); + TotalWrittenBlockSize_ += length; + ObtainNextBlock(); + } else { + memcpy(Current_, buffer, length); + Advance(length); + } +} + +ui64 TZeroCopyOutputStreamWriter::GetTotalWrittenSize() const +{ + return TotalWrittenBlockSize_ - RemainingBytes_; +} + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NSkiff |