diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/network/iovec.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/network/iovec.h')
-rw-r--r-- | util/network/iovec.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/util/network/iovec.h b/util/network/iovec.h new file mode 100644 index 0000000000..ac15a41f54 --- /dev/null +++ b/util/network/iovec.h @@ -0,0 +1,65 @@ +#pragma once + +#include <util/stream/output.h> +#include <util/system/types.h> +#include <util/system/yassert.h> + +class TContIOVector { + using TPart = IOutputStream::TPart; + +public: + inline TContIOVector(TPart* parts, size_t count) + : Parts_(parts) + , Count_(count) + { + } + + inline void Proceed(size_t len) noexcept { + while (Count_) { + if (len < Parts_->len) { + Parts_->len -= len; + Parts_->buf = (const char*)Parts_->buf + len; + + return; + } else { + len -= Parts_->len; + --Count_; + ++Parts_; + } + } + + if (len) { + Y_ASSERT(0 && "non zero length left"); + } + } + + inline const TPart* Parts() const noexcept { + return Parts_; + } + + inline size_t Count() const noexcept { + return Count_; + } + + static inline size_t Bytes(const TPart* parts, size_t count) noexcept { + size_t ret = 0; + + for (size_t i = 0; i < count; ++i) { + ret += parts[i].len; + } + + return ret; + } + + inline size_t Bytes() const noexcept { + return Bytes(Parts_, Count_); + } + + inline bool Complete() const noexcept { + return !Count(); + } + +private: + TPart* Parts_; + size_t Count_; +}; |