Skip to content

Commit

Permalink
spa-sys: Don't prefix enum name to enum variant bindings
Browse files Browse the repository at this point in the history
The enum variants are already named with prefixes, so this seems fairly
redundant.
  • Loading branch information
ids1024 committed Aug 3, 2022
1 parent 314ad46 commit 47a8e64
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 54 deletions.
1 change: 1 addition & 0 deletions libspa-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn main() {
.allowlist_type("spa_.*")
.allowlist_var("spa_.*")
.allowlist_var("SPA_.*")
.prepend_enum_name(false)
.derive_eq(true);

let builder = libs
Expand Down
22 changes: 8 additions & 14 deletions libspa/src/direction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ impl Direction {
/// The raw representation of the direction
pub fn as_raw(&self) -> spa_sys::spa_direction {
match self {
Self::Input => spa_sys::spa_direction_SPA_DIRECTION_INPUT,
Self::Output => spa_sys::spa_direction_SPA_DIRECTION_OUTPUT,
Self::Input => spa_sys::SPA_DIRECTION_INPUT,
Self::Output => spa_sys::SPA_DIRECTION_OUTPUT,
}
}

Expand All @@ -27,8 +27,8 @@ impl Direction {
/// This function will panic if `raw` is an invalid direction.
pub fn from_raw(raw: spa_sys::spa_direction) -> Self {
match raw {
spa_sys::spa_direction_SPA_DIRECTION_INPUT => Self::Input,
spa_sys::spa_direction_SPA_DIRECTION_OUTPUT => Self::Output,
spa_sys::SPA_DIRECTION_INPUT => Self::Input,
spa_sys::SPA_DIRECTION_OUTPUT => Self::Output,
_ => panic!("Invalid direction: {}", raw),
}
}
Expand All @@ -48,25 +48,19 @@ mod tests {

#[test]
fn as_raw() {
assert_eq!(
Direction::Input.as_raw(),
spa_sys::spa_direction_SPA_DIRECTION_INPUT
);
assert_eq!(
Direction::Output.as_raw(),
spa_sys::spa_direction_SPA_DIRECTION_OUTPUT
);
assert_eq!(Direction::Input.as_raw(), spa_sys::SPA_DIRECTION_INPUT);
assert_eq!(Direction::Output.as_raw(), spa_sys::SPA_DIRECTION_OUTPUT);
}

#[test]
fn from_raw() {
assert_eq!(
Direction::Input,
Direction::from_raw(spa_sys::spa_direction_SPA_DIRECTION_INPUT)
Direction::from_raw(spa_sys::SPA_DIRECTION_INPUT)
);
assert_eq!(
Direction::Output,
Direction::from_raw(spa_sys::spa_direction_SPA_DIRECTION_OUTPUT)
Direction::from_raw(spa_sys::SPA_DIRECTION_OUTPUT)
);
}

Expand Down
10 changes: 5 additions & 5 deletions libspa/src/pod/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,14 +643,14 @@ impl<'de, 'a> PodDeserializer<'de> {
let flags = ChoiceFlags::from_bits(flags).expect("invalid choice flags");

match choice_type {
spa_sys::spa_choice_type_SPA_CHOICE_None => {
spa_sys::SPA_CHOICE_None => {
if values.is_empty() {
Err(DeserializeError::MissingChoiceValues)
} else {
Ok(Choice(ChoiceFlags::empty(), ChoiceEnum::None(values[0])))
}
}
spa_sys::spa_choice_type_SPA_CHOICE_Range => {
spa_sys::SPA_CHOICE_Range => {
if values.len() < 3 {
Err(DeserializeError::MissingChoiceValues)
} else {
Expand All @@ -664,7 +664,7 @@ impl<'de, 'a> PodDeserializer<'de> {
))
}
}
spa_sys::spa_choice_type_SPA_CHOICE_Step => {
spa_sys::SPA_CHOICE_Step => {
if values.len() < 4 {
Err(DeserializeError::MissingChoiceValues)
} else {
Expand All @@ -679,7 +679,7 @@ impl<'de, 'a> PodDeserializer<'de> {
))
}
}
spa_sys::spa_choice_type_SPA_CHOICE_Enum => {
spa_sys::SPA_CHOICE_Enum => {
if values.is_empty() {
Err(DeserializeError::MissingChoiceValues)
} else {
Expand All @@ -692,7 +692,7 @@ impl<'de, 'a> PodDeserializer<'de> {
))
}
}
spa_sys::spa_choice_type_SPA_CHOICE_Flags => {
spa_sys::SPA_CHOICE_Flags => {
if values.is_empty() {
Err(DeserializeError::MissingChoiceValues)
} else {
Expand Down
18 changes: 7 additions & 11 deletions libspa/src/pod/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,32 +435,28 @@ impl<O: Write + Seek> PodSerializer<O> {
let flags = choice.0;

let (choice_type, values) = match &choice.1 {
ChoiceEnum::None(value) => (spa_sys::spa_choice_type_SPA_CHOICE_None, vec![value]),
ChoiceEnum::Range { default, min, max } => (
spa_sys::spa_choice_type_SPA_CHOICE_Range,
vec![default, min, max],
),
ChoiceEnum::None(value) => (spa_sys::SPA_CHOICE_None, vec![value]),
ChoiceEnum::Range { default, min, max } => {
(spa_sys::SPA_CHOICE_Range, vec![default, min, max])
}
ChoiceEnum::Step {
default,
min,
max,
step,
} => (
spa_sys::spa_choice_type_SPA_CHOICE_Step,
vec![default, min, max, step],
),
} => (spa_sys::SPA_CHOICE_Step, vec![default, min, max, step]),
ChoiceEnum::Enum {
default,
alternatives,
} => {
let mut values = vec![default];
values.extend(alternatives);
(spa_sys::spa_choice_type_SPA_CHOICE_Enum, values)
(spa_sys::SPA_CHOICE_Enum, values)
}
ChoiceEnum::Flags { default, flags } => {
let mut values = vec![default];
values.extend(flags);
(spa_sys::spa_choice_type_SPA_CHOICE_Flags, values)
(spa_sys::SPA_CHOICE_Flags, values)
}
};

Expand Down
46 changes: 22 additions & 24 deletions libspa/tests/pod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,10 +1371,10 @@ fn object() {
object_deserializer: &mut ObjectPodDeserializer<'de>,
) -> Result<Self::Value, DeserializeError<&'de [u8]>> {
let (device, _flags) = object_deserializer
.deserialize_property_key::<String>(spa_sys::spa_prop_SPA_PROP_device)?;
.deserialize_property_key::<String>(spa_sys::SPA_PROP_device)?;

let (frequency, _flags) = object_deserializer
.deserialize_property_key::<f32>(spa_sys::spa_prop_SPA_PROP_frequency)?;
.deserialize_property_key::<f32>(spa_sys::SPA_PROP_frequency)?;

Ok(MyProps { device, frequency })
}
Expand All @@ -1401,15 +1401,15 @@ fn object() {
&[] as &[u8],
Value::Object(Object {
type_: spa_sys::SPA_TYPE_OBJECT_Props,
id: spa_sys::spa_param_type_SPA_PARAM_Props,
id: spa_sys::SPA_PARAM_Props,
properties: vec![
Property {
key: spa_sys::spa_prop_SPA_PROP_device,
key: spa_sys::SPA_PROP_device,
flags: PropertyFlags::empty(),
value: Value::String("hw:0".into()),
},
Property {
key: spa_sys::spa_prop_SPA_PROP_frequency,
key: spa_sys::SPA_PROP_frequency,
flags: PropertyFlags::empty(),
value: Value::Float(440.0)
}
Expand All @@ -1424,18 +1424,16 @@ fn object() {
&self,
serializer: PodSerializer<O>,
) -> Result<SerializeSuccess<O>, cookie_factory::GenError> {
let mut obj_serializer = serializer.serialize_object(
spa_sys::SPA_TYPE_OBJECT_Props,
spa_sys::spa_param_type_SPA_PARAM_Props,
)?;
let mut obj_serializer = serializer
.serialize_object(spa_sys::SPA_TYPE_OBJECT_Props, spa_sys::SPA_PARAM_Props)?;

obj_serializer.serialize_property(
spa_sys::spa_prop_SPA_PROP_device,
spa_sys::SPA_PROP_device,
"hw:0",
PropertyFlags::empty(),
)?;
obj_serializer.serialize_property(
spa_sys::spa_prop_SPA_PROP_frequency,
spa_sys::SPA_PROP_frequency,
&440.0_f32,
PropertyFlags::empty(),
)?;
Expand Down Expand Up @@ -1482,7 +1480,7 @@ fn choice_range_f32() {
c::build_choice_f32(
vec_c.as_mut_ptr(),
vec_c.len(),
spa_sys::spa_choice_type_SPA_CHOICE_Range,
spa_sys::SPA_CHOICE_Range,
0,
3,
&[440.0_f32, 110.0, 880.0] as *const f32,
Expand Down Expand Up @@ -1534,7 +1532,7 @@ fn choice_range_i32() {
c::build_choice_i32(
vec_c.as_mut_ptr(),
vec_c.len(),
spa_sys::spa_choice_type_SPA_CHOICE_Range,
spa_sys::SPA_CHOICE_Range,
0,
3,
&[5, 2, 10] as *const i32,
Expand Down Expand Up @@ -1579,7 +1577,7 @@ fn choice_none_i32() {
c::build_choice_i32(
vec_c.as_mut_ptr(),
vec_c.len(),
spa_sys::spa_choice_type_SPA_CHOICE_None,
spa_sys::SPA_CHOICE_None,
0,
1,
&[5] as *const i32,
Expand Down Expand Up @@ -1632,7 +1630,7 @@ fn choice_step_i32() {
c::build_choice_i32(
vec_c.as_mut_ptr(),
vec_c.len(),
spa_sys::spa_choice_type_SPA_CHOICE_Step,
spa_sys::SPA_CHOICE_Step,
0,
4,
&[5, 2, 10, 1] as *const i32,
Expand Down Expand Up @@ -1683,7 +1681,7 @@ fn choice_enum_i32() {
c::build_choice_i32(
vec_c.as_mut_ptr(),
vec_c.len(),
spa_sys::spa_choice_type_SPA_CHOICE_Enum,
spa_sys::SPA_CHOICE_Enum,
0,
4,
&[5, 2, 10, 1] as *const i32,
Expand Down Expand Up @@ -1734,7 +1732,7 @@ fn choice_flags_i32() {
c::build_choice_i32(
vec_c.as_mut_ptr(),
vec_c.len(),
spa_sys::spa_choice_type_SPA_CHOICE_Flags,
spa_sys::SPA_CHOICE_Flags,
0,
4,
&[5, 2, 10, 1] as *const i32,
Expand Down Expand Up @@ -1786,7 +1784,7 @@ fn choice_range_i64() {
c::build_choice_i64(
vec_c.as_mut_ptr(),
vec_c.len(),
spa_sys::spa_choice_type_SPA_CHOICE_Range,
spa_sys::SPA_CHOICE_Range,
0,
3,
&[440_i64, 110, 880] as *const i64,
Expand Down Expand Up @@ -1838,7 +1836,7 @@ fn choice_range_f64() {
c::build_choice_f64(
vec_c.as_mut_ptr(),
vec_c.len(),
spa_sys::spa_choice_type_SPA_CHOICE_Range,
spa_sys::SPA_CHOICE_Range,
0,
3,
&[440.0_f64, 110.0, 880.0] as *const f64,
Expand Down Expand Up @@ -1889,7 +1887,7 @@ fn choice_enum_id() {
c::build_choice_id(
vec_c.as_mut_ptr(),
vec_c.len(),
spa_sys::spa_choice_type_SPA_CHOICE_Enum,
spa_sys::SPA_CHOICE_Enum,
0,
4,
&[5_u32, 2, 10, 1] as *const u32,
Expand Down Expand Up @@ -1952,7 +1950,7 @@ fn choice_enum_rectangle() {
c::build_choice_rectangle(
vec_c.as_mut_ptr(),
vec_c.len(),
spa_sys::spa_choice_type_SPA_CHOICE_Enum,
spa_sys::SPA_CHOICE_Enum,
0,
6,
&[800_u32, 600, 1920, 1080, 300, 200] as *const u32,
Expand Down Expand Up @@ -2003,7 +2001,7 @@ fn choice_enum_fraction() {
c::build_choice_fraction(
vec_c.as_mut_ptr(),
vec_c.len(),
spa_sys::spa_choice_type_SPA_CHOICE_Enum,
spa_sys::SPA_CHOICE_Enum,
0,
6,
&[1_u32, 2, 2, 3, 1, 3] as *const u32,
Expand Down Expand Up @@ -2054,7 +2052,7 @@ fn choice_enum_fd() {
c::build_choice_fd(
vec_c.as_mut_ptr(),
vec_c.len(),
spa_sys::spa_choice_type_SPA_CHOICE_Enum,
spa_sys::SPA_CHOICE_Enum,
0,
4,
&[5_i64, 2, 10, 1] as *const i64,
Expand Down Expand Up @@ -2088,7 +2086,7 @@ fn choice_extra_values() {
c::build_choice_i32(
vec_c.as_mut_ptr(),
vec_c.len(),
spa_sys::spa_choice_type_SPA_CHOICE_None,
spa_sys::SPA_CHOICE_None,
0,
1,
&[5, 6, 7, 8] as *const i32,
Expand Down

0 comments on commit 47a8e64

Please sign in to comment.