use std::sync::{Arc, OnceLock};
use crate::{
metadata::{
streams::Strings,
tables::{CodedIndex, CodedIndexType, Event, EventRc, TableInfoRef, TableRow},
token::Token,
typesystem::TypeRegistry,
},
Result,
};
#[derive(Clone, Debug)]
pub struct EventRaw {
pub rid: u32,
pub token: Token,
pub offset: usize,
pub flags: u32,
pub name: u32,
pub event_type: CodedIndex,
}
impl EventRaw {
pub fn to_owned(&self, strings: &Strings, types: &TypeRegistry) -> Result<EventRc> {
Ok(Arc::new(Event {
rid: self.rid,
token: self.token,
offset: self.offset,
flags: self.flags,
name: strings.get(self.name as usize)?.to_string(),
event_type: match types.get(&self.event_type.token) {
Some(parent) => parent.into(),
None => {
return Err(malformed_error!(
"Failed to resolve event type token - {}",
self.event_type.token.value()
))
}
},
fn_on_add: OnceLock::new(),
fn_on_other: OnceLock::new(),
fn_on_raise: OnceLock::new(),
fn_on_remove: OnceLock::new(),
custom_attributes: Arc::new(boxcar::Vec::new()),
}))
}
pub fn apply(&self) -> Result<()> {
Ok(())
}
}
impl TableRow for EventRaw {
#[rustfmt::skip]
fn row_size(sizes: &TableInfoRef) -> u32 {
u32::from(
2 +
sizes.str_bytes() +
sizes.coded_index_bytes(CodedIndexType::TypeDefOrRef)
)
}
}