void_core/metadata/
bundle.rs1use super::{hash_dir_path_u64, hash_path_u64, MetadataBundle, ShardMap, ShardRange};
4use void_crypto::RepoSecret;
5
6impl MetadataBundle {
7 pub const VERSION: u32 = 1;
8 pub const DEFAULT_RANGE_COUNT: u64 = 64;
9
10 pub fn new(repo_secret: RepoSecret, shard_map: ShardMap) -> Self {
12 Self {
13 version: Self::VERSION,
14 repo_secret,
15 shard_map,
16 }
17 }
18
19 pub fn with_default_map(repo_secret: RepoSecret) -> Self {
21 Self::new(repo_secret, ShardMap::new(Self::DEFAULT_RANGE_COUNT))
22 }
23
24 pub fn range_for_path(&self, path: &str) -> Option<&ShardRange> {
26 self.shard_map
27 .range_for_hash(hash_path_u64(&self.repo_secret, path))
28 }
29
30 pub fn range_for_dir(&self, dir_path: &str) -> Option<&ShardRange> {
32 self.shard_map
33 .range_for_hash(hash_dir_path_u64(&self.repo_secret, dir_path))
34 }
35}