ReadExtProtobuf

Trait ReadExtProtobuf 

Source
pub trait ReadExtProtobuf {
    // Required method
    fn read_protobuf_fields(self) -> ProtobufFieldIterator<Self> 
       where Self: Sized;
}
Expand description

Extension trait for reading raw Protocol Buffer fields from Read types

This trait provides low-level utilities for reading field-by-field from a byte stream. It returns owned data (Field<Vec<u8>>) suitable for streaming sources. It does not provide semantic interpretation - that is the caller’s responsibility.

§Example

use ::protobuf_core::{ReadExtProtobuf, Field, FieldValue};

fn main() -> Result<(), Box<dyn ::std::error::Error>> {
    let reader = &[0x08, 0x96, 0x01, 0x12, 0x03, 0x48, 0x65, 0x6c][..];

    for field in reader.read_protobuf_fields() {
        let field = field?;
        match field.value {
            FieldValue::Varint(varint) => {
                println!("Field {}: {}", field.field_number.as_u32(), varint.to_uint64());
            },
            FieldValue::Len(data) => {
                println!("Field {}: {:?}", field.field_number.as_u32(), data);
            },
            _ => {}
        }
    }
    Ok(())
}

Required Methods§

Source

fn read_protobuf_fields(self) -> ProtobufFieldIterator<Self>
where Self: Sized,

Read raw protobuf fields from the reader, returning an iterator

This consumes the reader and returns an iterator that yields fields sequentially. Each field contains raw bytes that must be interpreted by the caller. Returns owned data (Field<Vec<u8>>).

Implementors§

Source§

impl<R> ReadExtProtobuf for R
where R: Read,