2022-06-20 16:37:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
#include <caffe2/serialize/read_adapter_interface.h>
|
2024-09-12 03:27:06 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <cstring>
|
2022-06-20 16:37:38 +00:00
|
|
|
|
2024-09-12 03:27:06 +00:00
|
|
|
namespace caffe2::serialize {
|
2022-06-20 16:37:38 +00:00
|
|
|
|
|
|
|
|
class MemoryReadAdapter final : public caffe2::serialize::ReadAdapterInterface {
|
|
|
|
|
public:
|
|
|
|
|
explicit MemoryReadAdapter(const void* data, off_t size)
|
|
|
|
|
: data_(data), size_(size) {}
|
|
|
|
|
|
|
|
|
|
size_t size() const override {
|
|
|
|
|
return size_;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-12 03:27:06 +00:00
|
|
|
size_t read(
|
|
|
|
|
uint64_t pos,
|
|
|
|
|
void* buf,
|
|
|
|
|
size_t n,
|
|
|
|
|
const char* what [[maybe_unused]] = "") const override {
|
2022-06-20 16:37:38 +00:00
|
|
|
memcpy(buf, (int8_t*)(data_) + pos, n);
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const void* data_;
|
2024-09-12 03:27:06 +00:00
|
|
|
off_t size_{};
|
2022-06-20 16:37:38 +00:00
|
|
|
};
|
|
|
|
|
|
2024-09-12 03:27:06 +00:00
|
|
|
} // namespace caffe2::serialize
|