pub struct JsonPayload<T> { /* private fields */ }
Expand description
A wrapper that enables JSON-encoded event payloads in crate::event::AsyncEvent
and crate::event::PluginEvent
To store an arbitrary type as JSON inside the payload, make sure the data implements
Serialize
and Deserialize
from serde
and use JsonPayload<T>
as the payload type:
use falco_event::events::{AnyEventPayload, RawEvent};
use falco_plugin::event::{EventSource, JsonPayload, PluginEvent};
use falco_plugin::event::events::Event;
#[derive(serde::Serialize, serde::Deserialize)]
struct MyEvent {
param1: u32,
param2: u32,
}
impl EventSource for MyEvent {
const SOURCE: Option<&'static str> = Some("my_plugin");
}
// in a plugin trait implementation:
type Event<'a> = Event<PluginEvent<JsonPayload<MyEvent>>>;
Note: this SDK provides JSON support since it’s already necessary to talk
to the Falco Plugin API. JSON is not a good choice for high-volume events, as it takes
a lot of space and is pretty slow, compared to binary formats. See the source
of plugin::event:json
for what is needed to support a different serialization format
and consider using e.g. bincode instead.
Implementations§
Source§impl<T> JsonPayload<T>
impl<T> JsonPayload<T>
Sourcepub fn new(inner: T) -> Self
pub fn new(inner: T) -> Self
Create a JsonPayload
object from any data
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Return the wrapped data, dropping the wrapper
Trait Implementations§
Source§impl<T> Debug for JsonPayload<T>where
T: Debug,
impl<T> Debug for JsonPayload<T>where
T: Debug,
Source§impl<T> EventSource for JsonPayload<T>where
T: EventSource,
impl<T> EventSource for JsonPayload<T>where
T: EventSource,
Source§impl<'a, T> FromBytes<'a> for JsonPayload<T>where
T: DeserializeOwned,
impl<'a, T> FromBytes<'a> for JsonPayload<T>where
T: DeserializeOwned,
Source§fn from_bytes(buf: &mut &'a [u8]) -> Result<Self, FromBytesError>
fn from_bytes(buf: &mut &'a [u8]) -> Result<Self, FromBytesError>
Read the binary representation of a field and return the parsed representation Read more
§fn from_maybe_bytes(buf: Option<&mut &'a [u8]>) -> Result<Self, FromBytesError>
fn from_maybe_bytes(buf: Option<&mut &'a [u8]>) -> Result<Self, FromBytesError>
Read the binary representation of a field from a buffer that may or may not exist Read more
Source§impl<T> ToBytes for JsonPayload<T>where
T: Serialize,
impl<T> ToBytes for JsonPayload<T>where
T: Serialize,
Auto Trait Implementations§
impl<T> !Freeze for JsonPayload<T>
impl<T> !RefUnwindSafe for JsonPayload<T>
impl<T> Send for JsonPayload<T>where
T: Send,
impl<T> !Sync for JsonPayload<T>
impl<T> Unpin for JsonPayload<T>where
T: Unpin,
impl<T> !UnwindSafe for JsonPayload<T>
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