falco_event/events/
payload.rs1use crate::events::types::EventType;
2use crate::events::EventMetadata;
3use crate::fields::FromBytesError;
4use std::io::Write;
5use thiserror::Error;
6
7#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
8pub enum EventDirection {
9 Entry,
10 Exit,
11}
12
13pub trait EventPayload {
14 const ID: EventType;
15 const NAME: &'static str;
16
17 type LengthType;
18
19 fn direction() -> EventDirection {
20 match Self::ID as u32 % 2 {
21 0 => EventDirection::Entry,
22 1 => EventDirection::Exit,
23 _ => unreachable!(),
24 }
25 }
26}
27
28#[derive(Debug, Error)]
29pub enum PayloadFromBytesError {
30 #[error("failed to parse field {0}")]
32 NamedField(&'static str, #[source] FromBytesError),
33
34 #[error("type mismatch")]
36 TypeMismatch,
37
38 #[error("truncated event (wanted {wanted}, got {got})")]
40 TruncatedEvent { wanted: usize, got: usize },
41
42 #[error("unsupported event type {0}")]
44 UnsupportedEventType(u32),
45}
46
47pub trait PayloadToBytes {
48 fn binary_size(&self) -> usize;
49
50 fn write<W: Write>(&self, metadata: &EventMetadata, writer: W) -> std::io::Result<()>;
51}