diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/yson_pull/detail/byte_writer.h | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/yson_pull/detail/byte_writer.h')
-rw-r--r-- | library/cpp/yson_pull/detail/byte_writer.h | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/library/cpp/yson_pull/detail/byte_writer.h b/library/cpp/yson_pull/detail/byte_writer.h index 9a755912d7..dc1d4b4b96 100644 --- a/library/cpp/yson_pull/detail/byte_writer.h +++ b/library/cpp/yson_pull/detail/byte_writer.h @@ -9,69 +9,69 @@ #include <cstddef> #include <cstring> -namespace NYsonPull { - namespace NDetail { - template <class StreamCounter> - class byte_writer { - NYsonPull::NOutput::IStream& stream_; - StreamCounter stream_counter_; +namespace NYsonPull { + namespace NDetail { + template <class StreamCounter> + class byte_writer { + NYsonPull::NOutput::IStream& stream_; + StreamCounter stream_counter_; - public: - byte_writer(NYsonPull::NOutput::IStream& stream) - : stream_(stream) - { - } + public: + byte_writer(NYsonPull::NOutput::IStream& stream) + : stream_(stream) + { + } - // const-ness added to prevent direct stream mutation - const NYsonPull::NOutput::IStream& stream() { - return stream_; - } - const StreamCounter& counter() { - return stream_counter_; - } + // const-ness added to prevent direct stream mutation + const NYsonPull::NOutput::IStream& stream() { + return stream_; + } + const StreamCounter& counter() { + return stream_counter_; + } - void flush_buffer() { - stream_.flush_buffer(); - } + void flush_buffer() { + stream_.flush_buffer(); + } - void advance(size_t bytes) { - auto& buf = stream_.buffer(); - stream_counter_.update( - buf.pos(), - buf.pos() + bytes); - buf.advance(bytes); - } + void advance(size_t bytes) { + auto& buf = stream_.buffer(); + stream_counter_.update( + buf.pos(), + buf.pos() + bytes); + buf.advance(bytes); + } - void write(ui8 c) { - auto& buf = stream_.buffer(); + void write(ui8 c) { + auto& buf = stream_.buffer(); if (Y_LIKELY(!buf.is_full())) { - *buf.pos() = c; - advance(1); - } else { - auto ptr = reinterpret_cast<char*>(&c); - stream_counter_.update(&c, &c + 1); - stream_.flush_buffer({ptr, 1}); - } - } + *buf.pos() = c; + advance(1); + } else { + auto ptr = reinterpret_cast<char*>(&c); + stream_counter_.update(&c, &c + 1); + stream_.flush_buffer({ptr, 1}); + } + } - void write(const ui8* data, size_t size) { - auto& buf = stream_.buffer(); - auto free_buf = buf.available(); + void write(const ui8* data, size_t size) { + auto& buf = stream_.buffer(); + auto free_buf = buf.available(); if (Y_LIKELY(size < free_buf)) { - ::memcpy(buf.pos(), data, size); - advance(size); - } else { - if (!buf.is_full()) { - ::memcpy(buf.pos(), data, free_buf); - advance(free_buf); - data += free_buf; - size -= free_buf; - } - stream_counter_.update(data, data + size); - stream_.flush_buffer({reinterpret_cast<const char*>(data), - size}); - } + ::memcpy(buf.pos(), data, size); + advance(size); + } else { + if (!buf.is_full()) { + ::memcpy(buf.pos(), data, free_buf); + advance(free_buf); + data += free_buf; + size -= free_buf; + } + stream_counter_.update(data, data + size); + stream_.flush_buffer({reinterpret_cast<const char*>(data), + size}); + } } - }; + }; } -} +} |