hydrate_base/
built_artifact_metadata.rs1use crate::{ArtifactId, StringHash};
2use serde::{Deserialize, Serialize};
3use std::hash::{Hash, Hasher};
4use std::sync::Arc;
5use uuid::Uuid;
6
7#[derive(Serialize, Deserialize)]
10pub struct DebugArtifactManifestDataJson {
11 pub artifact_id: ArtifactId,
12 pub build_hash: String,
14 pub combined_build_hash: String,
15 pub symbol_name: String,
16 pub symbol_hash: String,
19 pub artifact_type: Uuid,
20 pub debug_name: String,
21}
22
23#[derive(Serialize, Deserialize, Default)]
26pub struct DebugManifestFileJson {
27 pub artifacts: Vec<DebugArtifactManifestDataJson>,
28}
29
30pub struct ArtifactManifestData {
35 pub artifact_id: ArtifactId,
36 pub simple_build_hash: u64,
37 pub combined_build_hash: u64,
38 pub symbol_hash: Option<StringHash>,
42 pub artifact_type: Uuid,
43 pub debug_name: Option<Arc<String>>,
45}
46
47const MAX_HEADER_SIZE: usize = 1024 * 1024;
51
52#[derive(Debug, Serialize, Deserialize)]
59pub struct BuiltArtifactHeaderData {
60 pub dependencies: Vec<ArtifactId>,
61 pub asset_type: Uuid, }
64
65impl Hash for BuiltArtifactHeaderData {
66 fn hash<H: Hasher>(
67 &self,
68 state: &mut H,
69 ) {
70 let mut dependencies_hash = 0;
71 for dependency in &self.dependencies {
72 dependencies_hash ^= dependency.0.as_u128();
73 }
74
75 dependencies_hash.hash(state);
76 self.asset_type.hash(state);
77 }
78}
79
80impl BuiltArtifactHeaderData {
81 pub fn write_header<T: std::io::Write>(
82 &self,
83 writer: &mut T,
84 ) -> std::io::Result<()> {
85 let serialized = bincode::serialize(self).unwrap();
86 let bytes = serialized.len();
87 assert!(bytes <= MAX_HEADER_SIZE);
89 writer.write(&bytes.to_le_bytes())?;
90 writer.write(&serialized)?;
91
92 Ok(())
93 }
94
95 pub fn read_header<T: std::io::Read>(
96 reader: &mut T
97 ) -> std::io::Result<BuiltArtifactHeaderData> {
98 let mut length_bytes = [0u8; 8];
99 reader.read(&mut length_bytes)?;
100 let length = usize::from_le_bytes(length_bytes);
101 assert!(length <= MAX_HEADER_SIZE);
102
103 let mut read_buffer = vec![0u8; length];
104 reader.read_exact(&mut read_buffer).unwrap();
105
106 let metadata = bincode::deserialize(&read_buffer).unwrap();
107 Ok(metadata)
108 }
109}