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 /library/cpp/binsaver/blob_io.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/binsaver/blob_io.h')
-rw-r--r-- | library/cpp/binsaver/blob_io.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/library/cpp/binsaver/blob_io.h b/library/cpp/binsaver/blob_io.h new file mode 100644 index 00000000000..abe518ef306 --- /dev/null +++ b/library/cpp/binsaver/blob_io.h @@ -0,0 +1,47 @@ +#pragma once + +#include "bin_saver.h" +#include "buffered_io.h" + +#include <util/memory/blob.h> + +class TYaBlobStream: public IBinaryStream { + TBlob Blob; + i64 Pos; + + int WriteImpl(const void*, int) override { + Y_ASSERT(0); + return 0; + } + int ReadImpl(void* userBuffer, int size) override { + if (size == 0) + return 0; + i64 res = Min<i64>(Blob.Length() - Pos, size); + if (res) + memcpy(userBuffer, ((const char*)Blob.Data()) + Pos, res); + Pos += res; + return res; + } + bool IsValid() const override { + return true; + } + bool IsFailed() const override { + return false; + } + +public: + TYaBlobStream(const TBlob& blob) + : Blob(blob) + , Pos(0) + { + } +}; + +template <class T> +inline void SerializeBlob(const TBlob& data, T& c) { + TYaBlobStream f(data); + { + IBinSaver bs(f, true); + bs.Add(1, &c); + } +} |