| Crates.io | prpc-serde-bytes |
| lib.rs | prpc-serde-bytes |
| version | 0.1.0 |
| created_at | 2024-04-18 04:02:22.571931+00 |
| updated_at | 2024-04-18 04:02:22.571931+00 |
| description | A procedural macro to add custom serialization and deserialization to prost bytes |
| homepage | https://github.com/Phala-Network/prpc |
| repository | |
| max_upload_size | |
| id | 1212100 |
| size | 6,656 |
prpc_serde_bytes is a Rust procedural macro designed to work with structs that utilize both Serde and Prost crate attributes. Specifically, this macro targets struct fields marked with #[prost(bytes = "vec")] and automatically adds #[serde(with = "as_bytes")] to them, enabling custom serialization behavior as specified.
Add prpc_serde_bytes as a dependency in your Cargo.toml:
[dependencies]
prpc-serde-bytes = "0.1.0"
use prpc_serde_bytes::prpc_serde_bytes;
#[prpc_serde_bytes("::hexed_bytes")]
#[derive(Serialize, Deserialize, prost::Message)]
pub struct Message {
#[prost(bytes = "vec", tag = "1")]
pub encoded: ::prost::alloc::vec::Vec<u8>,
#[prost(uint64, tag = "2")]
pub timestamp: u64,
}
Which will generate the following code:
#[derive(Serialize, Deserialize, prost::Message)]
pub struct Message {
#[prost(bytes = "vec", tag = "1")]
#[serde(with = "::hexed_bytes")]
pub encoded: ::prost::alloc::vec::Vec<u8>,
#[prost(uint64, tag = "2")]
pub timestamp: u64,
}