pub struct BlockReader<'a> { /* private fields */ }Expand description
Cursor-based TLV field reader for block bodies.
BlockReader wraps a byte slice and provides an iterator-like
interface for consuming TLV fields one at a time. It delegates
to the decode functions in bcp_types::fields but adds a
stateful cursor so the caller doesn’t have to manually track
offsets.
This is an internal implementation detail of the decoder — it is not part of the public API.
§Usage pattern
let mut reader = BlockReader::new(body);
while let Some(field) = reader.next_field()? {
match field.field_id {
1 => { /* handle field 1 */ }
2 => { /* handle field 2 */ }
_ => { /* skip unknown */ }
}
}Implementations§
Source§impl<'a> BlockReader<'a>
impl<'a> BlockReader<'a>
Sourcepub fn new(buf: &'a [u8]) -> Self
pub fn new(buf: &'a [u8]) -> Self
Create a new reader over the given body bytes.
The reader starts at position 0 and advances through the buffer
as fields are consumed via next_field.
Sourcepub fn next_field(&mut self) -> Result<Option<RawField<'a>>, DecodeError>
pub fn next_field(&mut self) -> Result<Option<RawField<'a>>, DecodeError>
Read the next TLV field from the body.
Returns Ok(Some(field)) if a field was successfully read, or
Ok(None) when the buffer is exhausted. Returns Err if the
field header or payload is malformed.
For Varint fields, data points to the varint bytes in the
original buffer (the caller should use decode_varint_value
to extract the value). For Bytes and Nested fields, data
is the raw payload after the length prefix.
§Errors
Returns DecodeError::Type or DecodeError::Wire if the
field header is malformed or the payload is truncated.