pub struct Encoder;Expand description
Provides the encoding engine for Protocol Buffers.
Implementations§
Source§impl Encoder
impl Encoder
Sourcepub fn encode<'a, W, F>(
&self,
field: (&u32, F),
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode<'a, W, F>( &self, field: (&u32, F), dst: &mut W, ) -> Result<usize, EncoderError>
Transforms a field into proto3 binary format and writes the result
into dst.
By default, the encoder uses mostly “standard” variant formats for
numbers. A developer can choose a specific format by passing the
EncoderLit.
use httlib_protos::{Encoder, EncoderLit};
let encoder = Encoder::default();
let mut dst = Vec::new();
encoder.encode((&1, &150i32), &mut dst).unwrap();
encoder.encode((&2, EncoderLit::SInt32(&-150i32)), &mut dst).unwrap();On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_bool<W>(
&self,
tag: &u32,
val: &bool,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_bool<W>( &self, tag: &u32, val: &bool, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided val into bool field with a specific tag
number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_bool_vec<W>(
&self,
tag: &u32,
vals: &Vec<bool>,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_bool_vec<W>( &self, tag: &u32, vals: &Vec<bool>, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided vals into bool repeated field with a specific
tag number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_int32<W>(
&self,
tag: &u32,
val: &i32,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_int32<W>( &self, tag: &u32, val: &i32, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided val into int32 field with a specific tag
number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_int32_vec<W>(
&self,
tag: &u32,
vals: &Vec<i32>,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_int32_vec<W>( &self, tag: &u32, vals: &Vec<i32>, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided vals into int32 repeated field with a specific
tag number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_int64<W>(
&self,
tag: &u32,
val: &i64,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_int64<W>( &self, tag: &u32, val: &i64, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided val into int64 field with a specific tag
number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_int64_vec<W>(
&self,
tag: &u32,
vals: &Vec<i64>,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_int64_vec<W>( &self, tag: &u32, vals: &Vec<i64>, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided vals into int64 repeated field with a specific
tag number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_uint32<W>(
&self,
tag: &u32,
val: &u32,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_uint32<W>( &self, tag: &u32, val: &u32, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided val into uint32 field with a specific tag
number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_uint32_vec<W>(
&self,
tag: &u32,
vals: &Vec<u32>,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_uint32_vec<W>( &self, tag: &u32, vals: &Vec<u32>, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided vals into uint32 repeated field with a
specific tag number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_uint64<W>(
&self,
tag: &u32,
val: &u64,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_uint64<W>( &self, tag: &u32, val: &u64, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided val into uint64 field with a specific tag
number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_uint64_vec<W>(
&self,
tag: &u32,
vals: &Vec<u64>,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_uint64_vec<W>( &self, tag: &u32, vals: &Vec<u64>, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided vals into uint64 repeated field with a
specific tag number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_float<W>(
&self,
tag: &u32,
val: &f32,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_float<W>( &self, tag: &u32, val: &f32, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided val into float field with a specific tag
number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_float_vec<W>(
&self,
tag: &u32,
vals: &Vec<f32>,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_float_vec<W>( &self, tag: &u32, vals: &Vec<f32>, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided vals into float repeated field with a specific
tag number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_double<W>(
&self,
tag: &u32,
val: &f64,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_double<W>( &self, tag: &u32, val: &f64, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided val into double field with a specific tag
number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_double_vec<W>(
&self,
tag: &u32,
vals: &Vec<f64>,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_double_vec<W>( &self, tag: &u32, vals: &Vec<f64>, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided vals into double repeated field with a
specific tag number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_bytes<W>(
&self,
tag: &u32,
val: &Vec<u8>,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_bytes<W>( &self, tag: &u32, val: &Vec<u8>, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided val into bytes field with a specific tag
number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_sint32<W>(
&self,
tag: &u32,
val: &i32,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_sint32<W>( &self, tag: &u32, val: &i32, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided val into sint32 field with a specific tag
number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_sint32_vec<W>(
&self,
tag: &u32,
vals: &Vec<i32>,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_sint32_vec<W>( &self, tag: &u32, vals: &Vec<i32>, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided vals into sin32 repeated field with a
specific tag number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_sint64<W>(
&self,
tag: &u32,
val: &i64,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_sint64<W>( &self, tag: &u32, val: &i64, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided val into sint64 field with a specific tag
number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_sint64_vec<W>(
&self,
tag: &u32,
vals: &Vec<i64>,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_sint64_vec<W>( &self, tag: &u32, vals: &Vec<i64>, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided vals into sin64 repeated field with a
specific tag number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_fixed32<W>(
&self,
tag: &u32,
val: &u32,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_fixed32<W>( &self, tag: &u32, val: &u32, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided val into fixed32 field with a specific tag
number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_fixed32_vec<W>(
&self,
tag: &u32,
vals: &Vec<u32>,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_fixed32_vec<W>( &self, tag: &u32, vals: &Vec<u32>, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided vals into fixed32 repeated field with a
specific tag number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_fixed64<W>(
&self,
tag: &u32,
val: &u64,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_fixed64<W>( &self, tag: &u32, val: &u64, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided val into fixed64 field with a specific tag
number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_fixed64_vec<W>(
&self,
tag: &u32,
vals: &Vec<u64>,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_fixed64_vec<W>( &self, tag: &u32, vals: &Vec<u64>, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided vals into fixed64 repeated field with a
specific tag number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_sfixed32<W>(
&self,
tag: &u32,
val: &i32,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_sfixed32<W>( &self, tag: &u32, val: &i32, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided val into sfixed32 field with a specific tag
number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_sfixed32_vec<W>(
&self,
tag: &u32,
vals: &Vec<i32>,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_sfixed32_vec<W>( &self, tag: &u32, vals: &Vec<i32>, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided vals into sfixed32 repeated field with a
specific tag number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_sfixed64<W>(
&self,
tag: &u32,
val: &i64,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_sfixed64<W>( &self, tag: &u32, val: &i64, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided val into sfixed64 field with a specific tag
number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.
Sourcepub fn encode_sfixed64_vec<W>(
&self,
tag: &u32,
vals: &Vec<i64>,
dst: &mut W,
) -> Result<usize, EncoderError>
pub fn encode_sfixed64_vec<W>( &self, tag: &u32, vals: &Vec<i64>, dst: &mut W, ) -> Result<usize, EncoderError>
Encodes the provided vals into sfixed64 repeated field with a
specific tag number and writes the resulting bytes into dst.
On success the number of written bytes is returned otherwise an error is thrown.