Skip to main content

azoth_core/traits/
event.rs

1use crate::error::Result;
2use crate::traits::projection::ProjectionTxn;
3use crate::types::EventId;
4
5/// Decoded event representation
6///
7/// Applications define their own event types and implement decoding
8#[derive(Debug, Clone)]
9pub struct DecodedEvent {
10    pub id: EventId,
11    pub event_type: String,
12    pub payload: Vec<u8>,
13}
14
15/// Event decoder: convert raw bytes to structured events
16pub trait EventDecoder: Send + Sync {
17    /// Decode raw event bytes
18    fn decode(&self, id: EventId, bytes: &[u8]) -> Result<DecodedEvent>;
19}
20
21/// Event applier: apply events to projection store
22///
23/// Note: Takes a mutable reference to the concrete transaction type,
24/// not a trait object, to avoid object-safety issues
25pub trait EventApplier<T: ProjectionTxn>: Send + Sync {
26    /// Apply a decoded event to the projection
27    fn apply(&self, txn: &mut T, event: &DecodedEvent) -> Result<()>;
28}