Crate prost_helper

Crate prost_helper 

Source
Expand description

A set of prost helper functions to make prost generated code easy to work with.

If you use prost-serde to build your protobuf files, mostly you need this crate to provide functions for is_zero and deserialize_null_default.

You can also use the macros to convert protobuf messages to / try_from Vec<u8>.

For example, if prost generated a data struct Hello, You can use the macros to generate From and /TryFrom respectively, and then use them:

use prost_helper::{prost_into_vec, vec_try_into_prost};
use prost::Message;

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

prost_into_vec!(Hello, 32);
vec_try_into_prost!(Hello);

fn send_hello(data: Vec<u8>) {
    unimplemented!();
}

let hello = Hello::default();
send_hello(hello.into());

Modules§

macros

Macros§

bytes_try_into_prost
prost_into_bytes
prost_into_vec
Generate From and Into for your prost message.
prost_to_json
vec_try_into_prost
Generate TryFrom and TryInto for your prost message from Vec<u8>.

Traits§

ToJson
Convert the prost message to JSON string for debugging purpose. Need serde_json support.

Functions§

deserialize_buf_bytes
deserialize_buf_vec
deserialize_id_bytes
deserialize_id_vec
deserialize_null_default
customized deserialize function to use default for JSON null value.
deserialize_repeat_buf_bytes
deserialize_repeat_buf_vec
deserialize_repeat_id_bytes
deserialize_repeat_id_vec
is_zero
customized skip_serializing_if function to skip 0 for numbers.
serialize_buf
serialize_id
serialize_repeat_buf
serialize_repeat_id