1. Cargo.toml
[dependencies]
prost = "0.11.9"
serde = { version = "1.0.152", features = ["derive"] }
2. src/main.rs
use prost::Message;
use serde::{Deserialize, Serialize};
use prost::bytes::Bytes;
#[derive(Clone, Message, Serialize, Deserialize)]
pub struct TestMessage {
#[prost(uint32, tag = "1")]
pub uint32_field: u32,
#[prost(string, tag = "2")]
pub string_filed: String,
}
fn main() {
let t = TestMessage { uint32_field: 1, string_filed: "string".to_string() };
let encoded_vec_u8 = t.encode_to_vec();
let buf = Bytes::from(encoded_vec_u8);
let decoded = TestMessage::decode(buf).unwrap();
println!("{decoded:?}");
}