TryIteratorExtProtobuf

Trait TryIteratorExtProtobuf 

Source
pub trait TryIteratorExtProtobuf {
    // Required method
    fn protobuf_fields(self) -> ProtobufFieldIteratorFromTryBytes<Self>
       where Self: Sized;
}
Expand description

Extension trait for reading raw Protocol Buffer fields from byte iterators that yield Result<u8, E>.

This trait provides convenient methods to read fields directly from any iterator that yields Result<u8, E>, allowing proper error propagation from I/O operations. Returns owned data (Field<Vec<u8>>).

§Example

use ::std::io::{Cursor, Read};
use ::protobuf_core::TryIteratorExtProtobuf;

let data = vec![0x08, 0x96, 0x01]; // field 1: 150
let mut reader = Cursor::new(data);
let iter = reader.bytes(); // Iterator<Item = Result<u8, io::Error>>
let fields: Vec<_> = iter.protobuf_fields().collect::<Result<Vec<_>, _>>().unwrap();
assert_eq!(fields[0].field_number.as_u32(), 1);

Required Methods§

Source

fn protobuf_fields(self) -> ProtobufFieldIteratorFromTryBytes<Self>
where Self: Sized,

Convert this iterator into an iterator of protobuf fields.

Returns an iterator that yields Result<Field<Vec<u8>>>. Each field is parsed from the byte stream sequentially. I/O errors from the underlying iterator are properly propagated.

Implementors§

Source§

impl<I, E> TryIteratorExtProtobuf for I
where I: Iterator<Item = Result<u8, E>>, E: Into<ProtobufError>,