Struct Encoder

Source
pub struct Encoder;
Expand description

Provides the encoding engine for Protocol Buffers.

Implementations§

Source§

impl Encoder

Source

pub const TAG_MIN: u32 = 1u32

A constant holding the minimum tag number of a field.

Source

pub const TAG_MAX: u32 = 536_870_911u32

A constant holding the maximum tag number of a field.

Source

pub fn encode<'a, W, F>( &self, field: (&u32, F), dst: &mut W, ) -> Result<usize, EncoderError>
where F: Into<EncoderLit<'a>>, W: ?Sized + Write,

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.

Source

pub fn encode_bool<W>( &self, tag: &u32, val: &bool, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_bool_vec<W>( &self, tag: &u32, vals: &Vec<bool>, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_int32<W>( &self, tag: &u32, val: &i32, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_int32_vec<W>( &self, tag: &u32, vals: &Vec<i32>, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_int64<W>( &self, tag: &u32, val: &i64, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_int64_vec<W>( &self, tag: &u32, vals: &Vec<i64>, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_uint32<W>( &self, tag: &u32, val: &u32, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_uint32_vec<W>( &self, tag: &u32, vals: &Vec<u32>, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_uint64<W>( &self, tag: &u32, val: &u64, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_uint64_vec<W>( &self, tag: &u32, vals: &Vec<u64>, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_float<W>( &self, tag: &u32, val: &f32, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_float_vec<W>( &self, tag: &u32, vals: &Vec<f32>, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_double<W>( &self, tag: &u32, val: &f64, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_double_vec<W>( &self, tag: &u32, vals: &Vec<f64>, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_bytes<W>( &self, tag: &u32, val: &Vec<u8>, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_sint32<W>( &self, tag: &u32, val: &i32, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_sint32_vec<W>( &self, tag: &u32, vals: &Vec<i32>, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_sint64<W>( &self, tag: &u32, val: &i64, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_sint64_vec<W>( &self, tag: &u32, vals: &Vec<i64>, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_fixed32<W>( &self, tag: &u32, val: &u32, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_fixed32_vec<W>( &self, tag: &u32, vals: &Vec<u32>, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_fixed64<W>( &self, tag: &u32, val: &u64, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_fixed64_vec<W>( &self, tag: &u32, vals: &Vec<u64>, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_sfixed32<W>( &self, tag: &u32, val: &i32, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_sfixed32_vec<W>( &self, tag: &u32, vals: &Vec<i32>, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_sfixed64<W>( &self, tag: &u32, val: &i64, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Source

pub fn encode_sfixed64_vec<W>( &self, tag: &u32, vals: &Vec<i64>, dst: &mut W, ) -> Result<usize, EncoderError>
where W: ?Sized + Write,

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.

Trait Implementations§

Source§

impl Default for Encoder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.