Skip to content

Commit

Permalink
enum, enum64: Map the ::signed() method to the BTF kind value
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrogario committed Nov 26, 2024
1 parent 1e8061d commit 95aa540
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/btf/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct NamedValue {
/// The name of the value
pub name: String,

/// The signed value
/// The integer value
pub value: IntegerValue,
}

Expand All @@ -50,6 +50,9 @@ struct Data {

/// A list of enum values
named_value_list: NamedValueList,

/// True if the enum is signed
signed: bool,
}

impl Data {
Expand Down Expand Up @@ -96,14 +99,16 @@ impl Data {
name,
size: type_header.size_or_type() as usize,
named_value_list,
signed,
})
}
}

define_type!(Enum, Data,
name: Option<String>,
size: usize,
named_value_list: NamedValueList
named_value_list: NamedValueList,
signed: bool
);

#[cfg(test)]
Expand Down Expand Up @@ -151,6 +156,7 @@ mod tests {
let type_header = Header::new(&mut reader, &file_header).unwrap();
let r#enum = Enum::new(&mut reader, &file_header, type_header).unwrap();
assert_eq!(*r#enum.size(), 4);
assert!(!*r#enum.signed());
assert!(!r#enum.header().kind_flag());
assert_eq!(r#enum.name().as_deref(), Some("State"));

Expand Down Expand Up @@ -207,6 +213,7 @@ mod tests {
let type_header = Header::new(&mut reader, &file_header).unwrap();
let r#enum = Enum::new(&mut reader, &file_header, type_header).unwrap();
assert_eq!(*r#enum.size(), 4);
assert!(*r#enum.signed());
assert!(r#enum.header().kind_flag());
assert_eq!(r#enum.name().as_deref(), Some("State"));

Expand Down
11 changes: 9 additions & 2 deletions src/btf/enum64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct NamedValue {
/// The name of the value
pub name: String,

/// The signed value
/// The integer value
pub value: IntegerValue,
}

Expand All @@ -50,6 +50,9 @@ struct Data {

/// A list of enum values
named_value_list: NamedValueList,

/// True if the enum is signed
signed: bool,
}

impl Data {
Expand Down Expand Up @@ -96,14 +99,16 @@ impl Data {
name,
size: type_header.size_or_type() as usize,
named_value_list,
signed,
})
}
}

define_type!(Enum64, Data,
name: Option<String>,
size: usize,
named_value_list: NamedValueList
named_value_list: NamedValueList,
signed: bool
);

#[cfg(test)]
Expand Down Expand Up @@ -151,6 +156,7 @@ mod tests {
let type_header = Header::new(&mut reader, &file_header).unwrap();
let enum64 = Enum64::new(&mut reader, &file_header, type_header).unwrap();
assert_eq!(*enum64.size(), 8);
assert!(!*enum64.signed());
assert!(!enum64.header().kind_flag());
assert_eq!(enum64.name().as_deref(), Some("State"));

Expand Down Expand Up @@ -207,6 +213,7 @@ mod tests {
let type_header = Header::new(&mut reader, &file_header).unwrap();
let enum64 = Enum64::new(&mut reader, &file_header, type_header).unwrap();
assert_eq!(*enum64.size(), 8);
assert!(*enum64.signed());
assert!(enum64.header().kind_flag());
assert_eq!(enum64.name().as_deref(), Some("State"));

Expand Down
2 changes: 2 additions & 0 deletions src/btf/type_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ mod tests {
name: String::from("Enum32Value1"),
value: IntegerValue32::Unsigned(0),
}],
false,
)),
);

Expand All @@ -834,6 +835,7 @@ mod tests {
name: String::from("Enum64Value1"),
value: IntegerValue64::Unsigned(0),
}],
false,
)),
);

Expand Down

0 comments on commit 95aa540

Please sign in to comment.