Struct httlib_protos::decoder::Decoder [−][src]
pub struct Decoder { /* fields omitted */ }Expand description
Provides the decoding engine for Protocol Buffers.
Implementations
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.