pub struct Decoder { /* private fields */ }
Expand description
Provides the decoding engine for Protocol Buffers.
Implementations§
Source§impl Decoder
impl Decoder
Sourcepub fn decode(
&mut self,
buf: &mut Vec<u8>,
dst: &mut Vec<(u32, Typ, Vec<u8>)>,
) -> Result<usize, DecoderError>
pub fn decode( &mut self, buf: &mut Vec<u8>, dst: &mut Vec<(u32, Typ, Vec<u8>)>, ) -> Result<usize, DecoderError>
Decodes proto3
encoded fields from the provided buf
and writes the
result into dst
.
The returned fields are tuples of format (tag, type, bytes)
where the
returned bytes
represent the encoded value. The developer should wrap
each value into the desired DecoderLit
and call parse
on it.
use httlib_protos::{Decoder, DecoderLit};
let mut decoder = Decoder::default();
let mut buf = vec![0x85, 0x35, 0x85];
let mut dst = vec![];
let size = decoder.decode(&mut buf, &mut dst).unwrap();
for (tag, typ, byt) in dst {
if tag == 1 {
i32::from(DecoderLit::Int32(byt));
}
}
This function consumes the buffer only if the decoding succeeds. The provided vector will stay untouched in case of an error or insufficient data.
On success, the number of written bytes is returned otherwise an error is thrown.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Decoder
impl RefUnwindSafe for Decoder
impl Send for Decoder
impl Sync for Decoder
impl Unpin for Decoder
impl UnwindSafe for Decoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more