1 | /* |
---|---|
2 | * SPDX-License-Identifier: Apache-2.0 |
3 | */ |
4 | |
5 | #pragma once |
6 | |
7 | #include "onnx/checker.h" |
8 | #include "onnx/common/path.h" |
9 | |
10 | #include <fstream> |
11 | |
12 | namespace ONNX_NAMESPACE { |
13 | |
14 | template <typename T> |
15 | void LoadProtoFromPath(const std::string proto_path, T& proto) { |
16 | std::fstream proto_stream(proto_path, std::ios::in | std::ios::binary); |
17 | if (!proto_stream.good()) { |
18 | fail_check("Unable to open proto file: ", proto_path, ". Please check if it is a valid proto. "); |
19 | } |
20 | std::string data{std::istreambuf_iterator<char>{proto_stream}, std::istreambuf_iterator<char>{}}; |
21 | if (!ParseProtoFromBytes(&proto, data.c_str(), data.size())) { |
22 | fail_check( |
23 | "Unable to parse proto from file: ", proto_path, ". Please check if it is a valid protobuf file of proto. "); |
24 | } |
25 | } |
26 | } // namespace ONNX_NAMESPACE |