blob: e0b7956a886b9994e0a0699ee9b9d9f7c0cc69fe (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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);
}
}
|