rive_rs/
runtime_header.rsuse std::collections::HashMap;
use crate::core::BinaryReader;
const FINGERPRINT: &[u8] = "RIVE".as_bytes();
#[derive(Debug)]
pub struct RuntimeHeader {
major_version: u32,
#[allow(unused)]
minor_version: u32,
#[allow(unused)]
file_id: u32,
property_to_field_index: HashMap<u32, u32>,
}
impl RuntimeHeader {
pub fn read(reader: &mut BinaryReader<'_>) -> Option<Self> {
if reader.read_bytes(FINGERPRINT.len())? != FINGERPRINT {
return None;
}
let major_version = reader.read_var_u64()? as u32;
let minor_version = reader.read_var_u64()? as u32;
let file_id = reader.read_var_u64()? as u32;
let mut property_keys = Vec::new();
loop {
let property_key = reader.read_var_u64()? as u32;
if property_key == 0 {
break;
}
property_keys.push(property_key);
}
let mut property_to_field_index = HashMap::new();
let mut current_u32 = 0;
let mut current_bit = 8;
for property_key in property_keys {
if current_bit == 8 {
current_u32 = reader.read_u32()?;
current_bit = 0;
}
let field_index = (current_u32 >> current_bit) & 3;
property_to_field_index.insert(property_key, field_index);
current_bit += 2;
}
Some(Self { major_version, minor_version, file_id, property_to_field_index })
}
pub fn major_version(&self) -> u32 {
self.major_version
}
pub fn property_file_id(&self, property_key: u32) -> Option<u32> {
self.property_to_field_index.get(&property_key).cloned()
}
}