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.

Trait Implementations

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.