pub struct RawEvent<'a> {
pub metadata: EventMetadata,
pub len: u32,
pub event_type: u16,
pub nparams: u32,
pub payload: &'a [u8],
}
Fields§
§metadata: EventMetadata
§len: u32
§event_type: u16
§nparams: u32
§payload: &'a [u8]
Implementations§
Source§impl<'e> RawEvent<'e>
impl<'e> RawEvent<'e>
Sourcepub fn from(buf: &[u8]) -> Result<RawEvent<'_>>
pub fn from(buf: &[u8]) -> Result<RawEvent<'_>>
Parse a byte slice into a RawEvent
This decodes the header while leaving the payload as a raw byte buffer.
Sourcepub fn trim(&mut self) -> Option<&'e [u8]>
pub fn trim(&mut self) -> Option<&'e [u8]>
Trim event payload
This limits the payload to the length actually indicated in the len
field
and returns the excess data. Useful when reading a raw event stream without
any external structure
Example
use falco_event::events::{PayloadFromBytesError, RawEvent};
let mut events: &[u8] = &[ /* raw event bytes */ ];
while !events.is_empty() {
let mut event = RawEvent::from(events)?;
match event.trim() {
Some(tail) => events = tail,
None => return Err(PayloadFromBytesError::TruncatedEvent {
wanted: event.len as usize,
got: events.len(),
})?
}
}
Sourcepub fn scan(buf: &'e [u8]) -> impl Iterator<Item = Result<RawEvent<'e>, Error>>
pub fn scan(buf: &'e [u8]) -> impl Iterator<Item = Result<RawEvent<'e>, Error>>
Iterate over a buffer with multiple raw events
This function takes a byte slice and returns an iterator that yields RawEvent
instances
until the whole buffer is consumed.
Sourcepub unsafe fn from_ptr<'a>(buf: *const u8) -> Result<RawEvent<'a>>
pub unsafe fn from_ptr<'a>(buf: *const u8) -> Result<RawEvent<'a>>
Parse a byte buffer (from a raw pointer) into a RawEvent
§Safety
buf
must point to a complete event, i.e.
- include the length field
- include
nparams
lengths - have enough data bytes for all the fields (sum of lengths)
pub fn load<'a, T: FromRawEvent<'e>>( &'a self, ) -> Result<Event<T>, PayloadFromBytesError>
Sourcepub fn params<T: LengthField>(
&self,
) -> Result<ParamIter<'e, T>, PayloadFromBytesError>
pub fn params<T: LengthField>( &self, ) -> Result<ParamIter<'e, T>, PayloadFromBytesError>
Get an iterator over the event parameters
T
must correspond to the type of the length field (u16 or u32, depending on the event type)
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for RawEvent<'a>
impl<'a> RefUnwindSafe for RawEvent<'a>
impl<'a> Send for RawEvent<'a>
impl<'a> Sync for RawEvent<'a>
impl<'a> Unpin for RawEvent<'a>
impl<'a> UnwindSafe for RawEvent<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more