1 | #pragma once |
---|---|
2 | |
3 | #include <istream> |
4 | |
5 | #include "c10/macros/Macros.h" |
6 | #include "caffe2/serialize/read_adapter_interface.h" |
7 | |
8 | namespace caffe2 { |
9 | namespace serialize { |
10 | |
11 | // this is a reader implemented by std::istream |
12 | class TORCH_API IStreamAdapter final : public ReadAdapterInterface { |
13 | public: |
14 | C10_DISABLE_COPY_AND_ASSIGN(IStreamAdapter); |
15 | explicit IStreamAdapter(std::istream* istream); |
16 | size_t size() const override; |
17 | size_t read(uint64_t pos, void* buf, size_t n, const char* what = "") |
18 | const override; |
19 | ~IStreamAdapter() override; |
20 | |
21 | private: |
22 | std::istream* istream_; |
23 | void validate(const char* what) const; |
24 | }; |
25 | |
26 | } // namespace serialize |
27 | } // namespace caffe2 |
28 |