use std::sync::{Arc, OnceLock};
use crate::{
metadata::{
streams::{Blob, Strings},
tables::{
Assembly, AssemblyFlagsValue, AssemblyRc, HashAlgorithmId, TableInfoRef, TableRow,
},
token::Token,
},
Result,
};
#[derive(Clone, Debug)]
pub struct AssemblyRaw {
pub rid: u32,
pub token: Token,
pub offset: usize,
pub hash_alg_id: u32,
pub major_version: u32,
pub minor_version: u32,
pub build_number: u32,
pub revision_number: u32,
pub flags: u32,
pub public_key: u32,
pub name: u32,
pub culture: u32,
}
impl AssemblyRaw {
pub fn to_owned(&self, strings: &Strings, blobs: &Blob) -> Result<AssemblyRc> {
Ok(Arc::new(Assembly {
rid: self.rid,
token: self.token,
offset: self.offset,
hash_alg_id: HashAlgorithmId(self.hash_alg_id),
major_version: self.major_version,
minor_version: self.minor_version,
build_number: self.build_number,
revision_number: self.revision_number,
flags: AssemblyFlagsValue(self.flags),
public_key: if self.public_key == 0 {
None
} else {
Some(blobs.get(self.public_key as usize)?.to_vec())
},
name: strings.get(self.name as usize)?.to_string(),
culture: if self.culture == 0 {
None
} else {
Some(strings.get(self.culture as usize)?.to_string())
},
security: OnceLock::new(),
custom_attributes: Arc::new(boxcar::Vec::new()),
}))
}
pub fn apply(&self) -> Result<()> {
Ok(())
}
}
impl TableRow for AssemblyRaw {
#[rustfmt::skip]
fn row_size(sizes: &TableInfoRef) -> u32 {
u32::from(
4 +
2 +
2 +
2 +
2 +
4 +
sizes.blob_bytes() +
sizes.str_bytes() +
sizes.str_bytes()
)
}
}