Skip to main content

qcow/header_ext/
feature_name.rs

1use super::*;
2
3/// An enum representing the different types of features
4#[derive_binread]
5#[derive(Debug)]
6#[br(repr(u8))]
7pub enum FeatureKind {
8    /// Feature belongs to the backwards incompatible feature set
9    IncompatibleFeature = 0,
10
11    /// Feature belongs to the backwards compatible feature set
12    CompatibleFeatures = 1,
13
14    /// Feature belogns to the autocleared features
15    AutoClearFeatures = 2,
16}
17
18/// A struct representing a feature/name pair
19#[derive_binread]
20#[derive(Debug)]
21pub struct FeatureName {
22    /// The type of feature being named
23    pub kind: FeatureKind,
24
25    /// The bit number within the feature being named, with 0 being the least significant bit
26    pub bit_number: u8,
27
28    #[br(temp, count = 0x2e)]
29    feature_name_bytes: Vec<u8>,
30
31    /// The name of the feature pointed to by the feature kind and the bit number
32    #[br(calc = {
33        feature_name_bytes.retain(|&x| x != 0);
34        String::from_utf8_lossy(&feature_name_bytes).into_owned()
35    })]
36    pub feature_name: String,
37}