hdds_gen/codegen/
type_hash.rs1#[must_use]
8pub fn compute_type_id(fqn: &str) -> u32 {
9 const FNV_PRIME: u32 = 16_777_619;
10 const FNV_OFFSET: u32 = 2_166_136_261;
11
12 let mut hash = FNV_OFFSET;
13 for byte in fqn.as_bytes() {
14 hash ^= u32::from(*byte);
15 hash = hash.wrapping_mul(FNV_PRIME);
16 }
17 hash
18}
19
20#[cfg(test)]
21mod tests {
22 use super::compute_type_id;
23
24 #[test]
25 fn test_fnv_reproducible() {
26 let name = "sensor::Temperature";
27 let id1 = compute_type_id(name);
28 let id2 = compute_type_id(name);
29 assert_eq!(id1, id2);
30 }
31}