Skip to content

bindgen: default bitmask enums to no flags set - #576

Open
Mattbusel wants to merge 1 commit into
mavlink:masterfrom
Mattbusel:fix/bitflags-default-empty
Open

Mattbusel wants to merge 1 commit into
mavlink:masterfrom
Mattbusel:fix/bitflags-default-empty

Conversation

@Mattbusel

@Mattbusel Mattbusel commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #557.

emit_const_default used entries[0] for every enum, so bitmask enums defaulted to their first flag. For example GimbalDeviceCapFlags::default() was GIMBAL_DEVICE_CAP_FLAGS_HAS_RETRACT, which means a default GIMBAL_DEVICE_INFORMATION_DATA claimed a retract capability.

Fix: bitmask enums now emit pub const DEFAULT: Self = Self::empty();. Regular enums still use the first entry.

Regression test: mavlink/tests/bitflags_default_test.rs checks GimbalDeviceCapFlags, HlFailureFlag, MavProtocolCapability and a default GIMBAL_DEVICE_INFORMATION_DATA.

Results:

  • Both tests fail without the change and pass with it.
  • Snapshots updated for mav_bool and undersized_bitflag; only the DEFAULT lines change.
  • serde_test::test_ser_de_heartbeat updated: a default HEARTBEAT_DATA now serializes base_mode as "" (no flags) instead of "MAV_MODE_FLAG_SAFETY_ARMED". The old expectation encoded the Make 0 default for bitflags #557 bug.
  • cargo fmt --all -- --check is clean.

MavBool still defaults to false (MAV_BOOL_FALSE is 0), so as_bool() doesn't change.

@onur-ozkan onur-ozkan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks clean, thanks!

Could you please fix the CI errors and re-push the changes (into same commit)?

@Mattbusel
Mattbusel force-pushed the fix/bitflags-default-empty branch from 2cb5d52 to 9f8760d Compare November 17, 2026 05:33
Bitflag enums used the first declared flag as DEFAULT, so default
messages carried a set flag (e.g. GIMBAL_DEVICE_CAP_FLAGS_HAS_RETRACT).
Bitmasks now default to empty(); regular enums keep entries[0].

Fixes mavlink#557
@Mattbusel
Mattbusel force-pushed the fix/bitflags-default-empty branch from 9f8760d to ac09b4e Compare November 17, 2026 07:56

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make 0 default for bitflags

2 participants