Rajeev Ranjan
Rajeev Ranjan

Reputation: 4076

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?

Upvotes: 0

Views: 1644

Answers (2)

Yevgeniy Shchemelev
Yevgeniy Shchemelev

Reputation: 3651

Take a look here: https://github.com/jgarzik/rust-protobuf-example/tree/master

You don't need to define parse_from_bytes yourself.

Upvotes: 2

Stargateur
Stargateur

Reputation: 26727

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.

Upvotes: 2

Related Questions