#prost-build #protobuf #prost #serde-derive #serde #derive

build prost-build-config

A prost toolkit to build protobuf with extra derive/attrs support

6 releases

0.6.3 Dec 21, 2023
0.6.1 Dec 20, 2023
0.5.0 Oct 7, 2022
0.4.1 Jan 22, 2022

#162 in Build Utils

Download history 261/week @ 2023-11-26 464/week @ 2023-12-03 213/week @ 2023-12-10 296/week @ 2023-12-17 104/week @ 2023-12-24 240/week @ 2023-12-31 347/week @ 2024-01-07 640/week @ 2024-01-14 408/week @ 2024-01-21 476/week @ 2024-01-28 258/week @ 2024-02-04 659/week @ 2024-02-11 1351/week @ 2024-02-18 1969/week @ 2024-02-25 2009/week @ 2024-03-03 372/week @ 2024-03-10

5,821 downloads per month
Used in 2 crates (via rings-rpc)

MIT license

11KB
112 lines

prost-helper

Two crates are provided to facilitate prost to better work with protobuf:

  • prost-build-config: help you to generate serde compatible code with prost and protobuf files. More in documentation.
  • prost-helper: macros and functions to facilitate prost. More in documentation.

Using prost-helper in a Cargo Project

First, add prost-build-config and prost-helper to your Cargo.toml:

[dependencies]
prost-helper = "0.6"

[build-dependencies]
prost-build-config = "0.4"

Then copy the prost-build-config/default_build_config.yml to your project and customize it. See more information in prost-build-config/examples/build_config.yml. Then you could add this in your build.rs:

use prost_build_config::{BuildConfig, Builder};

fn main() {
    let config: BuildConfig = serde_yaml::from_str(include_str!("path/to/your/build_config.yml")).unwrap();
    Builder::from(config).build_protos();
}

That's it!

If you'd like to generate the implementation for From trait to Vec<u8>, or TryFrom trait from Vec<u8> to protobuf data structure, you could use prost_into_vec! and vec_try_into_prost! macros. Here is an example:

use prost::Message;
use std::convert::TryInto;

#[derive(Clone, PartialEq, Eq, Message)]
pub struct Hello {
    #[prost(string, tag = "1")]
    pub msg: String,
}

// implement the traits
prost_into_vec!(Hello, 32);
vec_try_into_prost!(Hello);


let hello = Hello::default();

// use `Into` to convert message to `Vec<u8>`
let data: Vec<u8> = hello.into();

// use `TryInto` to convert `Vec<u8>` back to message
let hello_result: Result<Hello, prost::DecodeError> = data.try_into();

Have fun with prost!

License

prost-helper is distributed under the terms of MIT.

See LICENSE for details.

Copyright 2021 Tyr Chen

Dependencies

~8–20MB
~266K SLoC