Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:20:22

0001 // Copyright (c) ONNX Project Contributors
0002 
0003 /*
0004  * SPDX-License-Identifier: Apache-2.0
0005  */
0006 
0007 #pragma once
0008 
0009 #include <filesystem>
0010 #include <fstream>
0011 #include <string>
0012 
0013 #include "onnx/checker.h"
0014 #include "onnx/common/path.h"
0015 
0016 namespace ONNX_NAMESPACE {
0017 
0018 template <typename T>
0019 void LoadProtoFromPath(const std::string proto_path, T& proto) {
0020   std::filesystem::path proto_u8_path = std::filesystem::u8path(proto_path);
0021   std::fstream proto_stream(proto_u8_path, std::ios::in | std::ios::binary);
0022   if (!proto_stream.good()) {
0023     fail_check("Unable to open proto file: ", proto_path, ". Please check if it is a valid proto. ");
0024   }
0025   std::string data{std::istreambuf_iterator<char>{proto_stream}, std::istreambuf_iterator<char>{}};
0026   if (!ParseProtoFromBytes(&proto, data.c_str(), data.size())) {
0027     fail_check(
0028         "Unable to parse proto from file: ", proto_path, ". Please check if it is a valid protobuf file of proto. ");
0029   }
0030 }
0031 } // namespace ONNX_NAMESPACE