onnx_runtime_loader/proto.rs
1//! ONNX protobuf decoding (ยง19.1).
2//!
3//! The `onnx` submodule contains the `prost`-generated types compiled from the
4//! vendored `proto/onnx.proto3` (see `build.rs`). [`decode_model`] parses a
5//! serialized `ModelProto` from bytes.
6
7use prost::Message;
8
9use crate::LoaderError;
10
11/// The `prost`-generated ONNX protobuf types (package `onnx`).
12#[allow(clippy::all, missing_docs, non_snake_case)]
13pub mod onnx {
14 include!(concat!(env!("OUT_DIR"), "/onnx.rs"));
15}
16
17pub use onnx::ModelProto;
18
19/// Decode a [`ModelProto`] from serialized protobuf bytes.
20pub fn decode_model(bytes: &[u8]) -> Result<ModelProto, LoaderError> {
21 ModelProto::decode(bytes).map_err(|e| LoaderError::ProtobufParse(e.to_string()))
22}