use serde::de::DeserializeOwned;
use crate::payload;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct StreamEvent {
pub offset: i64,
pub stream: String,
pub key: Option<String>,
pub payload: Vec<u8>,
pub created_at: i64,
}
impl StreamEvent {
#[doc(hidden)]
pub fn from_row(
offset: i64,
stream: String,
key: Option<String>,
payload: Vec<u8>,
created_at: i64,
) -> Self {
Self {
offset,
stream,
key,
payload,
created_at,
}
}
pub fn payload_as<T: DeserializeOwned>(&self) -> crate::Result<T> {
payload::payload_as(&self.payload)
}
}