// Copyright (c) ONNX Project Contributors /* * SPDX-License-Identifier: Apache-2.0 */ #pragma once #include #include #include #include "onnx/checker.h" #include "onnx/common/path.h" namespace ONNX_NAMESPACE { template void LoadProtoFromPath(const std::string proto_path, T& proto) { std::filesystem::path proto_u8_path = std::filesystem::u8path(proto_path); std::fstream proto_stream(proto_u8_path, std::ios::in | std::ios::binary); if (!proto_stream.good()) { fail_check("Unable to open proto file: ", proto_path, ". Please check if it is a valid proto. "); } std::string data{std::istreambuf_iterator{proto_stream}, std::istreambuf_iterator{}}; if (!ParseProtoFromBytes(&proto, data.c_str(), data.size())) { fail_check( "Unable to parse proto from file: ", proto_path, ". Please check if it is a valid protobuf file of proto. "); } } } // namespace ONNX_NAMESPACE