use std::sync::Arc;
use crate::{
metadata::{
streams::{Blob, Guid, Strings},
tables::{Document, DocumentRc, TableInfoRef, TableRow},
token::Token,
},
Result,
};
#[derive(Clone, Debug)]
pub struct DocumentRaw {
pub rid: u32,
pub token: Token,
pub offset: usize,
pub name: u32,
pub hash_algorithm: u32,
pub hash: u32,
pub language: u32,
}
impl DocumentRaw {
pub fn to_owned(&self, _strings: &Strings, blobs: &Blob, guids: &Guid) -> Result<DocumentRc> {
let name_blob = blobs.get(self.name as usize)?;
let name = String::from_utf8_lossy(name_blob).to_string();
let hash_algorithm_guid = guids.get(self.hash_algorithm as usize)?;
let hash_bytes = if self.hash == 0 {
Vec::new()
} else {
blobs.get(self.hash as usize)?.to_vec()
};
let language_guid = guids.get(self.language as usize)?;
let document = Document {
rid: self.rid,
token: self.token,
offset: self.offset,
name,
hash_algorithm: hash_algorithm_guid,
hash: hash_bytes,
language: language_guid,
};
Ok(Arc::new(document))
}
}
impl TableRow for DocumentRaw {
#[rustfmt::skip]
fn row_size(sizes: &TableInfoRef) -> u32 {
u32::from(
sizes.blob_bytes()
.saturating_add(sizes.guid_bytes())
.saturating_add(sizes.blob_bytes())
.saturating_add(sizes.guid_bytes())
)
}
}