use crate::{ArtifactId, StringHash};
use serde::{Deserialize, Serialize};
use std::hash::{Hash, Hasher};
use std::sync::Arc;
use uuid::Uuid;
#[derive(Serialize, Deserialize)]
pub struct DebugArtifactManifestDataJson {
pub artifact_id: ArtifactId,
pub build_hash: String,
pub combined_build_hash: String,
pub symbol_name: String,
pub symbol_hash: String,
pub artifact_type: Uuid,
pub debug_name: String,
}
#[derive(Serialize, Deserialize, Default)]
pub struct DebugManifestFileJson {
pub artifacts: Vec<DebugArtifactManifestDataJson>,
}
pub struct ArtifactManifestData {
pub artifact_id: ArtifactId,
pub simple_build_hash: u64,
pub combined_build_hash: u64,
pub symbol_hash: Option<StringHash>,
pub artifact_type: Uuid,
pub debug_name: Option<Arc<String>>,
}
const MAX_HEADER_SIZE: usize = 1024 * 1024;
#[derive(Debug, Serialize, Deserialize)]
pub struct BuiltArtifactHeaderData {
pub dependencies: Vec<ArtifactId>,
pub asset_type: Uuid, }
impl Hash for BuiltArtifactHeaderData {
fn hash<H: Hasher>(
&self,
state: &mut H,
) {
let mut dependencies_hash = 0;
for dependency in &self.dependencies {
dependencies_hash ^= dependency.0.as_u128();
}
dependencies_hash.hash(state);
self.asset_type.hash(state);
}
}
impl BuiltArtifactHeaderData {
pub fn write_header<T: std::io::Write>(
&self,
writer: &mut T,
) -> std::io::Result<()> {
let serialized = bincode::serialize(self).unwrap();
let bytes = serialized.len();
assert!(bytes <= MAX_HEADER_SIZE);
writer.write(&bytes.to_le_bytes())?;
writer.write(&serialized)?;
Ok(())
}
pub fn read_header<T: std::io::Read>(
reader: &mut T
) -> std::io::Result<BuiltArtifactHeaderData> {
let mut length_bytes = [0u8; 8];
reader.read(&mut length_bytes)?;
let length = usize::from_le_bytes(length_bytes);
assert!(length <= MAX_HEADER_SIZE);
let mut read_buffer = vec![0u8; length];
reader.read_exact(&mut read_buffer).unwrap();
let metadata = bincode::deserialize(&read_buffer).unwrap();
Ok(metadata)
}
}