wip render repo

This commit is contained in:
Pascal Engélibert 2026-03-29 12:00:57 +02:00
commit 145e3c592e
6 changed files with 190 additions and 50 deletions

View file

@ -14,8 +14,9 @@ const VERSION: [u8; 1] = [0];
#[derive(Debug)]
pub struct RepoMetadata {
pub date: u64,
pub commit_url: String,
content: Vec<u8>,
pub repo_url: String,
pub commit_hash: String,
pub content: Vec<u8>,
}
#[derive(Debug)]
@ -74,9 +75,13 @@ impl RepoMetadata {
let now = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
file.write_all(&now.to_be_bytes())?;
file.write_all(&(self.commit_url.len() as u32).to_be_bytes())?;
file.write_all(&(self.repo_url.len() as u32).to_be_bytes())?;
file.write_all(self.commit_url.as_bytes())?;
file.write_all(self.repo_url.as_bytes())?;
file.write_all(&(self.commit_hash.len() as u32).to_be_bytes())?;
file.write_all(self.commit_hash.as_bytes())?;
file.write_all(&self.content)?;
@ -99,23 +104,35 @@ impl RepoMetadata {
file.read_exact(&mut date)?;
let date = u64::from_be_bytes(date);
let mut commit_url_len = [0u8; 4];
file.read_exact(&mut commit_url_len)?;
let commit_url_len = u32::from_be_bytes(commit_url_len) as usize;
if commit_url_len > MAX_URL_SIZE {
let mut repo_url_len = [0u8; 4];
file.read_exact(&mut repo_url_len)?;
let repo_url_len = u32::from_be_bytes(repo_url_len) as usize;
if repo_url_len > MAX_URL_SIZE {
return Err(ReadRepoMetadataError::InvalidFormat);
}
let mut commit_url = vec![0; commit_url_len];
file.read_exact(&mut commit_url)?;
let commit_url = String::from_utf8(commit_url)?;
let mut repo_url = vec![0; repo_url_len];
file.read_exact(&mut repo_url)?;
let repo_url = String::from_utf8(repo_url)?;
let mut commit_hash_len = [0u8; 4];
file.read_exact(&mut commit_hash_len)?;
let commit_hash_len = u32::from_be_bytes(commit_hash_len) as usize;
if commit_hash_len > MAX_URL_SIZE {
return Err(ReadRepoMetadataError::InvalidFormat);
}
let mut commit_hash = vec![0; commit_hash_len];
file.read_exact(&mut commit_hash)?;
let commit_hash = String::from_utf8(commit_hash)?;
let mut content = Vec::new();
file.read_to_end(&mut content)?;
Ok(Self {
date,
commit_url,
repo_url,
commit_hash,
content,
})
}