1 | #pragma once |
---|---|
2 | #include <cstring> |
3 | #include <caffe2/serialize/read_adapter_interface.h> |
4 | |
5 | |
6 | namespace caffe2 { |
7 | namespace serialize { |
8 | |
9 | class MemoryReadAdapter final : public caffe2::serialize::ReadAdapterInterface { |
10 | public: |
11 | explicit MemoryReadAdapter(const void* data, off_t size) |
12 | : data_(data), size_(size) {} |
13 | |
14 | size_t size() const override { |
15 | return size_; |
16 | } |
17 | |
18 | size_t read(uint64_t pos, void* buf, size_t n, const char* what = "") |
19 | const override { |
20 | (void) what; |
21 | memcpy(buf, (int8_t*)(data_) + pos, n); |
22 | return n; |
23 | } |
24 | |
25 | private: |
26 | const void* data_; |
27 | off_t size_; |
28 | }; |
29 | |
30 | |
31 | } // namespace serialize |
32 | } // namespace caffe2 |
33 |