Skip to content

Commit

Permalink
Represent btf::types::Enum64 values as i128
Browse files Browse the repository at this point in the history
Similar to what we did with Enum and storing i64 values, represent
Enum64 values as i128.

Signed-off-by: Daniel Müller <deso@posteo.net>
  • Loading branch information
d-e-s-o committed Dec 11, 2024
1 parent 1dc07a2 commit f3ebab9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions libbpf-rs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased
----------
- Adjusted `btf::types::EnumMember` to store value as `i64`
- Adjusted `btf::types::Enum64Member` to store value as `i128`


0.25.0-beta.0
Expand Down
11 changes: 8 additions & 3 deletions libbpf-rs/src/btf/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,15 +834,20 @@ gen_collection_concrete_type! {
/// The name of this enum variant.
pub name: Option<&'btf OsStr>,
/// The numeric value of this enum variant.
pub value: u64,
pub value: i128,
}

|btf, member| Enum64Member {
|btf, member, signed| Enum64Member {
name: btf.name_at(member.name_off),
value: {
let hi: u64 = member.val_hi32.into();
let lo: u64 = member.val_lo32.into();
hi << 32 | lo
let val = hi << 32 | lo;
if signed {
i64::from_ne_bytes(val.to_ne_bytes()).into()
} else {
val.into()
}
},
}
}
Expand Down

0 comments on commit f3ebab9

Please sign in to comment.