noir_protobuf

Trait ProtoCodec

Source
pub trait ProtoCodec<T, R> {
Show 19 methods // Required methods fn encode(value: &T) -> R; fn decode(value: &R) -> Result<T>; // Provided methods fn encode_some(value: &T) -> Option<R> { ... } fn encode_enum(value: &T) -> i32 where R: Into<i32> { ... } fn encode_vec<'a, I>(values: I) -> Vec<R> where I: IntoIterator<Item = &'a T>, T: 'a { ... } fn decode_wrap(value: &R, msg: &'static str) -> Result<T> { ... } fn decode_vec(values: &[R]) -> Result<Vec<T>> { ... } fn decode_vec_wrap(values: &[R], msg: &'static str) -> Result<Vec<T>> { ... } fn decode_arr<const N: usize>(values: &[R]) -> Result<[T; N]> { ... } fn decode_arr_wrap<const N: usize>( values: &[R], msg: &'static str, ) -> Result<[T; N]> { ... } fn decode_box_arr<const N: usize>(values: &[R]) -> Result<Box<[T; N]>> { ... } fn decode_box_arr_wrap<const N: usize>( values: &[R], msg: &'static str, ) -> Result<Box<[T; N]>> { ... } fn decode_some(value: &Option<R>) -> Result<T> { ... } fn decode_some_wrap(value: &Option<R>, msg: &'static str) -> Result<T> { ... } fn decode_opt_wrap( value: &Option<R>, msg: &'static str, ) -> Result<Option<T>> { ... } fn decode_enum(value: i32) -> Result<T> where R: TryFrom<i32, Error = UnknownEnumValue> { ... } fn decode_enum_wrap(value: i32, msg: &'static str) -> Result<T> where R: TryFrom<i32, Error = UnknownEnumValue> { ... } fn serialize_to_vec(value: &T) -> Vec<u8> where R: Message { ... } fn deserialize_from_slice(buf: &[u8]) -> Result<T> where R: Message + Default { ... }
}
Expand description

A protobuf codec to convert between a domain type T and its protobuf representation R.

It is to be implemented on a Self independent of T and R, so that T can be in a third party crate, and Self can be generic in the F field type as well, which would be cumbersome if we had to implement traits on R because T is in another crate from the schema, or to scatter the .proto schema around so that the traits can be co-defined with T which is what can actually be generic in F.

Required Methods§

Source

fn encode(value: &T) -> R

Convert domain type T to protobuf representation R.

Source

fn decode(value: &R) -> Result<T>

Try to convert protobuf representation R to domain type T.

Provided Methods§

Source

fn encode_some(value: &T) -> Option<R>

Encode a field as Some.

Source

fn encode_enum(value: &T) -> i32
where R: Into<i32>,

Encode an enum to the i32 value that prost represents it with.

Source

fn encode_vec<'a, I>(values: I) -> Vec<R>
where I: IntoIterator<Item = &'a T>, T: 'a,

Encode multiple values as a vector.

Source

fn decode_wrap(value: &R, msg: &'static str) -> Result<T>

Decode a field and attach the name of the field if it fails.

Source

fn decode_vec(values: &[R]) -> Result<Vec<T>>

Decode multiple values into a vector.

Source

fn decode_vec_wrap(values: &[R], msg: &'static str) -> Result<Vec<T>>

Decode multiple values into a vector, attaching a field name to any errors.

Source

fn decode_arr<const N: usize>(values: &[R]) -> Result<[T; N]>

Decode a fixed size array.

Source

fn decode_arr_wrap<const N: usize>( values: &[R], msg: &'static str, ) -> Result<[T; N]>

Decode a fixed size array, attaching a field name to any errors

Source

fn decode_box_arr<const N: usize>(values: &[R]) -> Result<Box<[T; N]>>

Decode a boxed fixed size array.

Source

fn decode_box_arr_wrap<const N: usize>( values: &[R], msg: &'static str, ) -> Result<Box<[T; N]>>

Decode a boxed fixed size array, attaching a field name to any errors

Source

fn decode_some(value: &Option<R>) -> Result<T>

Decode an optional field as a required one; fails if it’s None.

Source

fn decode_some_wrap(value: &Option<R>, msg: &'static str) -> Result<T>

Decode an optional field as a required one, attaching a field name to any errors. Returns error if the field is missing.

Source

fn decode_opt_wrap(value: &Option<R>, msg: &'static str) -> Result<Option<T>>

Decode an optional field, attaching a field name to any errors. Return None if the field is missing.

Source

fn decode_enum(value: i32) -> Result<T>
where R: TryFrom<i32, Error = UnknownEnumValue>,

Decode the numeric representation of an enum into the domain type. Return an error if the value cannot be recognized.

Source

fn decode_enum_wrap(value: i32, msg: &'static str) -> Result<T>
where R: TryFrom<i32, Error = UnknownEnumValue>,

Decode the numeric representation of an enum, attaching the field name to any errors.

Source

fn serialize_to_vec(value: &T) -> Vec<u8>
where R: Message,

Encode a domain type to protobuf and serialize it to bytes.

Source

fn deserialize_from_slice(buf: &[u8]) -> Result<T>
where R: Message + Default,

Deserialize a buffer into protobuf and then decode into the domain type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§