use myko::prelude::*;
#[myko_item]
pub struct LogEntry {
pub project_id: String,
pub cbor_b64: String,
pub created: String,
}
impl LogEntry {
pub fn wrap(event_id: &str, project_id: &str, cbor_bytes: &[u8], created: &str) -> Self {
use base64::Engine as _;
LogEntry {
id: event_id.into(),
project_id: project_id.into(),
cbor_b64: base64::engine::general_purpose::STANDARD.encode(cbor_bytes),
created: created.into(),
}
}
pub fn cbor_bytes(&self) -> anyhow::Result<Vec<u8>> {
use base64::Engine as _;
Ok(base64::engine::general_purpose::STANDARD.decode(&self.cbor_b64)?)
}
pub fn unwrap_event(&self) -> anyhow::Result<myko::wire::MEvent> {
Ok(ciborium::from_reader(self.cbor_bytes()?.as_slice())?)
}
}