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 e1bdb6a commit 4cc8eea
Showing 1 changed file with 8 additions and 3 deletions.
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 4cc8eea

Please sign in to comment.