Struct RawEvent

Source
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>

Source

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.

Source

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(),
        })?
    }
}
Source

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.

Source

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)
Source

pub fn load<'a, T: FromRawEvent<'e>>( &'a self, ) -> Result<Event<T>, PayloadFromBytesError>

Source

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)

Source§

impl<'e> RawEvent<'e>

Trait Implementations§

Source§

impl<'a> Debug for RawEvent<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl EventToBytes for RawEvent<'_>

Source§

fn binary_size(&self) -> usize

Source§

fn write<W: Write>(&self, writer: W) -> Result<()>

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.