Search code examples
rustprotocol-buffers

How can I use protobuf::parse_from_bytes for a Rust struct?


I have defined a ProcessState structure:

#[derive(Clone, Debug, PartialEq, Default)]
pub struct ProcessState {
    pub file_sample: FileSample,
    pub estimate: Estimate,
    pub estimate_cache: HashMap<String, Estimate>,
    pub total_count: u64,
    pub systems: HashMap<String, SystemState>,
    pub aggregate_clock: u64,
    pub aggregate_mean: f64,
    pub file_samples: VecDeque<FileSample>,
}

How do I make use of the parse_from_bytes function on this? Do I need to define a proto message for my structure in order to use this method?


Solution

  • If I understand how this works, you can't implement this yourself: the API is designed to generate Rust code from a .proto file.

    The doc says that the recommended way is to use protoc-rust to generate the code.

    As for what to write in the .proto file, the doc is here.