// ============================================================================
// AUTO-GENERATED BY lycvvt/mavlink XML Code Generator — DO NOT EDIT MANUALLY
// Dialect version: 3, dialect id: 0
// ============================================================================

///|
/// Micro air vehicle / autopilot classes.
pub(all) enum MavAutopilot {
  Generic
  Ardupilotmega
  Invalid
  Px4
} derive(Eq, Debug)

///|
pub extend MavAutopilot with Eq::{not_equal, equal}

///|
pub extend MavAutopilot with @debug.Debug::{to_repr}

///|
/// Convert `MavAutopilot` to its raw MAVLink numeric value.
pub fn MavAutopilot::to_uint(self : MavAutopilot) -> UInt32 {
  match self {
    Generic => 0U
    Ardupilotmega => 3U
    Invalid => 8U
    Px4 => 12U
  }
}

///|
/// Decode `MavAutopilot` from its raw MAVLink numeric value.
pub fn MavAutopilot::from_uint(v : UInt32) -> MavAutopilot? {
  match v {
    0U => Some(Generic)
    3U => Some(Ardupilotmega)
    8U => Some(Invalid)
    12U => Some(Px4)
    _ => None
  }
}

///|
/// MAVLINK component type reported in HEARTBEAT message.
pub(all) enum MavType {
  Generic
  FixedWing
  Quadrotor
  Gcs
  GroundRover
  Submarine
  Hexarotor
  Octorotor
  VtolTailsitter
} derive(Eq, Debug)

///|
pub extend MavType with Eq::{not_equal, equal}

///|
pub extend MavType with @debug.Debug::{to_repr}

///|
/// Convert `MavType` to its raw MAVLink numeric value.
pub fn MavType::to_uint(self : MavType) -> UInt32 {
  match self {
    Generic => 0U
    FixedWing => 1U
    Quadrotor => 2U
    Gcs => 6U
    GroundRover => 10U
    Submarine => 12U
    Hexarotor => 13U
    Octorotor => 14U
    VtolTailsitter => 22U
  }
}

///|
/// Decode `MavType` from its raw MAVLink numeric value.
pub fn MavType::from_uint(v : UInt32) -> MavType? {
  match v {
    0U => Some(Generic)
    1U => Some(FixedWing)
    2U => Some(Quadrotor)
    6U => Some(Gcs)
    10U => Some(GroundRover)
    12U => Some(Submarine)
    13U => Some(Hexarotor)
    14U => Some(Octorotor)
    22U => Some(VtolTailsitter)
    _ => None
  }
}

///|
/// These flags encode the MAV mode.
pub(all) enum MavModeFlag {
  CustomModeEnabled
  TestEnabled
  AutoEnabled
  GuidedEnabled
  StabilizeEnabled
  HilEnabled
  ManualInputEnabled
  SafetyArmed
} derive(Eq, Debug)

///|
pub extend MavModeFlag with Eq::{not_equal, equal}

///|
pub extend MavModeFlag with @debug.Debug::{to_repr}

///|
/// Convert `MavModeFlag` to its raw MAVLink numeric value.
pub fn MavModeFlag::to_uint(self : MavModeFlag) -> UInt32 {
  match self {
    CustomModeEnabled => 1U
    TestEnabled => 2U
    AutoEnabled => 4U
    GuidedEnabled => 8U
    StabilizeEnabled => 16U
    HilEnabled => 32U
    ManualInputEnabled => 64U
    SafetyArmed => 128U
  }
}

///|
/// Decode `MavModeFlag` from its raw MAVLink numeric value.
pub fn MavModeFlag::from_uint(v : UInt32) -> MavModeFlag? {
  match v {
    1U => Some(CustomModeEnabled)
    2U => Some(TestEnabled)
    4U => Some(AutoEnabled)
    8U => Some(GuidedEnabled)
    16U => Some(StabilizeEnabled)
    32U => Some(HilEnabled)
    64U => Some(ManualInputEnabled)
    128U => Some(SafetyArmed)
    _ => None
  }
}

///|
/// Indicates the current state of the vehicle.
pub(all) enum MavState {
  Uninit
  Boot
  Calibrating
  Standby
  Active
  Critical
  Emergency
  Poweroff
  FlightTermination
} derive(Eq, Debug)

///|
pub extend MavState with Eq::{not_equal, equal}

///|
pub extend MavState with @debug.Debug::{to_repr}

///|
/// Convert `MavState` to its raw MAVLink numeric value.
pub fn MavState::to_uint(self : MavState) -> UInt32 {
  match self {
    Uninit => 0U
    Boot => 1U
    Calibrating => 2U
    Standby => 3U
    Active => 4U
    Critical => 5U
    Emergency => 6U
    Poweroff => 7U
    FlightTermination => 8U
  }
}

///|
/// Decode `MavState` from its raw MAVLink numeric value.
pub fn MavState::from_uint(v : UInt32) -> MavState? {
  match v {
    0U => Some(Uninit)
    1U => Some(Boot)
    2U => Some(Calibrating)
    3U => Some(Standby)
    4U => Some(Active)
    5U => Some(Critical)
    6U => Some(Emergency)
    7U => Some(Poweroff)
    8U => Some(FlightTermination)
    _ => None
  }
}

///|
/// Component ids (values) for the different types and instances of onboard hardware/software.
pub(all) enum MavComponent {
  MavCompIdAll
  MavCompIdAutopilot1
  MavCompIdCamera
  MavCompIdGimbal
  MavCompIdMissionplanner
  MavCompIdOnboardComputer
  MavCompIdGps
} derive(Eq, Debug)

///|
pub extend MavComponent with Eq::{not_equal, equal}

///|
pub extend MavComponent with @debug.Debug::{to_repr}

///|
/// Convert `MavComponent` to its raw MAVLink numeric value.
pub fn MavComponent::to_uint(self : MavComponent) -> UInt32 {
  match self {
    MavCompIdAll => 0U
    MavCompIdAutopilot1 => 1U
    MavCompIdCamera => 100U
    MavCompIdGimbal => 154U
    MavCompIdMissionplanner => 190U
    MavCompIdOnboardComputer => 191U
    MavCompIdGps => 220U
  }
}

///|
/// Decode `MavComponent` from its raw MAVLink numeric value.
pub fn MavComponent::from_uint(v : UInt32) -> MavComponent? {
  match v {
    0U => Some(MavCompIdAll)
    1U => Some(MavCompIdAutopilot1)
    100U => Some(MavCompIdCamera)
    154U => Some(MavCompIdGimbal)
    190U => Some(MavCompIdMissionplanner)
    191U => Some(MavCompIdOnboardComputer)
    220U => Some(MavCompIdGps)
    _ => None
  }
}

///|
/// Commands to be executed by the MAV.
pub(all) enum MavCmd {
  NavWaypoint
  NavLoiterUnlim
  NavReturnToLaunch
  NavLand
  NavTakeoff
  DoSetMode
  DoChangeSpeed
  DoSetServo
  ComponentArmDisarm
  SetMessageInterval
  RequestMessage
  RequestAutopilotCapabilities
} derive(Eq, Debug)

///|
pub extend MavCmd with Eq::{not_equal, equal}

///|
pub extend MavCmd with @debug.Debug::{to_repr}

///|
/// Convert `MavCmd` to its raw MAVLink numeric value.
pub fn MavCmd::to_uint(self : MavCmd) -> UInt32 {
  match self {
    NavWaypoint => 16U
    NavLoiterUnlim => 17U
    NavReturnToLaunch => 20U
    NavLand => 21U
    NavTakeoff => 22U
    DoSetMode => 176U
    DoChangeSpeed => 178U
    DoSetServo => 183U
    ComponentArmDisarm => 400U
    SetMessageInterval => 511U
    RequestMessage => 512U
    RequestAutopilotCapabilities => 520U
  }
}

///|
/// Decode `MavCmd` from its raw MAVLink numeric value.
pub fn MavCmd::from_uint(v : UInt32) -> MavCmd? {
  match v {
    16U => Some(NavWaypoint)
    17U => Some(NavLoiterUnlim)
    20U => Some(NavReturnToLaunch)
    21U => Some(NavLand)
    22U => Some(NavTakeoff)
    176U => Some(DoSetMode)
    178U => Some(DoChangeSpeed)
    183U => Some(DoSetServo)
    400U => Some(ComponentArmDisarm)
    511U => Some(SetMessageInterval)
    512U => Some(RequestMessage)
    520U => Some(RequestAutopilotCapabilities)
    _ => None
  }
}

///|
/// Result from a MAVLink command (MAV_CMD).
pub(all) enum MavResult {
  Accepted
  TemporarilyRejected
  Denied
  Unsupported
  Failed
  InProgress
  Cancelled
} derive(Eq, Debug)

///|
pub extend MavResult with Eq::{not_equal, equal}

///|
pub extend MavResult with @debug.Debug::{to_repr}

///|
/// Convert `MavResult` to its raw MAVLink numeric value.
pub fn MavResult::to_uint(self : MavResult) -> UInt32 {
  match self {
    Accepted => 0U
    TemporarilyRejected => 1U
    Denied => 2U
    Unsupported => 3U
    Failed => 4U
    InProgress => 5U
    Cancelled => 6U
  }
}

///|
/// Decode `MavResult` from its raw MAVLink numeric value.
pub fn MavResult::from_uint(v : UInt32) -> MavResult? {
  match v {
    0U => Some(Accepted)
    1U => Some(TemporarilyRejected)
    2U => Some(Denied)
    3U => Some(Unsupported)
    4U => Some(Failed)
    5U => Some(InProgress)
    6U => Some(Cancelled)
    _ => None
  }
}

///|
/// Indicates the severity level, generally used for status messages.
pub(all) enum MavSeverity {
  Emergency
  Alert
  Critical
  Error
  Warning
  Notice
  Info
  Debug
} derive(Eq, Debug)

///|
pub extend MavSeverity with Eq::{not_equal, equal}

///|
pub extend MavSeverity with @debug.Debug::{to_repr}

///|
/// Convert `MavSeverity` to its raw MAVLink numeric value.
pub fn MavSeverity::to_uint(self : MavSeverity) -> UInt32 {
  match self {
    Emergency => 0U
    Alert => 1U
    Critical => 2U
    Error => 3U
    Warning => 4U
    Notice => 5U
    Info => 6U
    Debug => 7U
  }
}

///|
/// Decode `MavSeverity` from its raw MAVLink numeric value.
pub fn MavSeverity::from_uint(v : UInt32) -> MavSeverity? {
  match v {
    0U => Some(Emergency)
    1U => Some(Alert)
    2U => Some(Critical)
    3U => Some(Error)
    4U => Some(Warning)
    5U => Some(Notice)
    6U => Some(Info)
    7U => Some(Debug)
    _ => None
  }
}

///|
/// Type of GPS fix.
pub(all) enum GpsFixType {
  NoGps
  NoFix
  V2dFix
  V3dFix
  Dgps
  RtkFloat
  RtkFixed
} derive(Eq, Debug)

///|
pub extend GpsFixType with Eq::{not_equal, equal}

///|
pub extend GpsFixType with @debug.Debug::{to_repr}

///|
/// Convert `GpsFixType` to its raw MAVLink numeric value.
pub fn GpsFixType::to_uint(self : GpsFixType) -> UInt32 {
  match self {
    NoGps => 0U
    NoFix => 1U
    V2dFix => 2U
    V3dFix => 3U
    Dgps => 4U
    RtkFloat => 5U
    RtkFixed => 6U
  }
}

///|
/// Decode `GpsFixType` from its raw MAVLink numeric value.
pub fn GpsFixType::from_uint(v : UInt32) -> GpsFixType? {
  match v {
    0U => Some(NoGps)
    1U => Some(NoFix)
    2U => Some(V2dFix)
    3U => Some(V3dFix)
    4U => Some(Dgps)
    5U => Some(RtkFloat)
    6U => Some(RtkFixed)
    _ => None
  }
}

///|
/// Coordinate frames used by MAVLink mission items and position messages.
pub(all) enum MavCoordFrame {
  Global
  LocalNed
  Mission
  GlobalRelativeAlt
  LocalEnu
  GlobalInt
  GlobalRelativeAltInt
  BodyNed
} derive(Eq, Debug)

///|
pub extend MavCoordFrame with Eq::{not_equal, equal}

///|
pub extend MavCoordFrame with @debug.Debug::{to_repr}

///|
/// Convert `MavCoordFrame` to its raw MAVLink numeric value.
pub fn MavCoordFrame::to_uint(self : MavCoordFrame) -> UInt32 {
  match self {
    Global => 0U
    LocalNed => 1U
    Mission => 2U
    GlobalRelativeAlt => 3U
    LocalEnu => 4U
    GlobalInt => 5U
    GlobalRelativeAltInt => 6U
    BodyNed => 8U
  }
}

///|
/// Decode `MavCoordFrame` from its raw MAVLink numeric value.
pub fn MavCoordFrame::from_uint(v : UInt32) -> MavCoordFrame? {
  match v {
    0U => Some(Global)
    1U => Some(LocalNed)
    2U => Some(Mission)
    3U => Some(GlobalRelativeAlt)
    4U => Some(LocalEnu)
    5U => Some(GlobalInt)
    6U => Some(GlobalRelativeAltInt)
    8U => Some(BodyNed)
    _ => None
  }
}

///|
/// Result of a MAVLink mission operation (MAV_MISSION_ACK).
pub(all) enum MavMissionResult {
  MavMissionAccepted
  MavMissionError
  MavMissionUnsupportedFrame
  MavMissionUnsupported
  MavMissionNoSpace
  MavMissionInvalid
  MavMissionInvalidSequence
  MavMissionDenied
  MavMissionOperationCancelled
} derive(Eq, Debug)

///|
pub extend MavMissionResult with Eq::{not_equal, equal}

///|
pub extend MavMissionResult with @debug.Debug::{to_repr}

///|
/// Convert `MavMissionResult` to its raw MAVLink numeric value.
pub fn MavMissionResult::to_uint(self : MavMissionResult) -> UInt32 {
  match self {
    MavMissionAccepted => 0U
    MavMissionError => 1U
    MavMissionUnsupportedFrame => 2U
    MavMissionUnsupported => 3U
    MavMissionNoSpace => 4U
    MavMissionInvalid => 5U
    MavMissionInvalidSequence => 13U
    MavMissionDenied => 14U
    MavMissionOperationCancelled => 15U
  }
}

///|
/// Decode `MavMissionResult` from its raw MAVLink numeric value.
pub fn MavMissionResult::from_uint(v : UInt32) -> MavMissionResult? {
  match v {
    0U => Some(MavMissionAccepted)
    1U => Some(MavMissionError)
    2U => Some(MavMissionUnsupportedFrame)
    3U => Some(MavMissionUnsupported)
    4U => Some(MavMissionNoSpace)
    5U => Some(MavMissionInvalid)
    13U => Some(MavMissionInvalidSequence)
    14U => Some(MavMissionDenied)
    15U => Some(MavMissionOperationCancelled)
    _ => None
  }
}

///|
/// Type of mission items being requested, uploaded, or cleared.
pub(all) enum MavMissionType {
  Mission
  Fence
  Rally
  All
} derive(Eq, Debug)

///|
pub extend MavMissionType with Eq::{not_equal, equal}

///|
pub extend MavMissionType with @debug.Debug::{to_repr}

///|
/// Convert `MavMissionType` to its raw MAVLink numeric value.
pub fn MavMissionType::to_uint(self : MavMissionType) -> UInt32 {
  match self {
    Mission => 0U
    Fence => 1U
    Rally => 2U
    All => 255U
  }
}

///|
/// Decode `MavMissionType` from its raw MAVLink numeric value.
pub fn MavMissionType::from_uint(v : UInt32) -> MavMissionType? {
  match v {
    0U => Some(Mission)
    1U => Some(Fence)
    2U => Some(Rally)
    255U => Some(All)
    _ => None
  }
}

///|
/// Specifies the datatype of a MAVLink parameter.
pub(all) enum MavParamType {
  Uint8
  Int8
  Uint16
  Int16
  Uint32
  Int32
  Uint64
  Int64
  Real32
  Real64
} derive(Eq, Debug)

///|
pub extend MavParamType with Eq::{not_equal, equal}

///|
pub extend MavParamType with @debug.Debug::{to_repr}

///|
/// Convert `MavParamType` to its raw MAVLink numeric value.
pub fn MavParamType::to_uint(self : MavParamType) -> UInt32 {
  match self {
    Uint8 => 1U
    Int8 => 2U
    Uint16 => 3U
    Int16 => 4U
    Uint32 => 5U
    Int32 => 6U
    Uint64 => 7U
    Int64 => 8U
    Real32 => 9U
    Real64 => 10U
  }
}

///|
/// Decode `MavParamType` from its raw MAVLink numeric value.
pub fn MavParamType::from_uint(v : UInt32) -> MavParamType? {
  match v {
    1U => Some(Uint8)
    2U => Some(Int8)
    3U => Some(Uint16)
    4U => Some(Int16)
    5U => Some(Uint32)
    6U => Some(Int32)
    7U => Some(Uint64)
    8U => Some(Int64)
    9U => Some(Real32)
    10U => Some(Real64)
    _ => None
  }
}

///|
/// Data stream IDs for telemetry rate configuration.
pub(all) enum MavDataStream {
  All
  RawSensors
  ExtendedStatus
  RcChannels
  RawController
  Position
  Extra1
  Extra2
  Extra3
} derive(Eq, Debug)

///|
pub extend MavDataStream with Eq::{not_equal, equal}

///|
pub extend MavDataStream with @debug.Debug::{to_repr}

///|
/// Convert `MavDataStream` to its raw MAVLink numeric value.
pub fn MavDataStream::to_uint(self : MavDataStream) -> UInt32 {
  match self {
    All => 0U
    RawSensors => 1U
    ExtendedStatus => 2U
    RcChannels => 3U
    RawController => 4U
    Position => 6U
    Extra1 => 10U
    Extra2 => 11U
    Extra3 => 12U
  }
}

///|
/// Decode `MavDataStream` from its raw MAVLink numeric value.
pub fn MavDataStream::from_uint(v : UInt32) -> MavDataStream? {
  match v {
    0U => Some(All)
    1U => Some(RawSensors)
    2U => Some(ExtendedStatus)
    3U => Some(RcChannels)
    4U => Some(RawController)
    6U => Some(Position)
    10U => Some(Extra1)
    11U => Some(Extra2)
    12U => Some(Extra3)
    _ => None
  }
}

///|
/// Enumeration of distance sensor types.
pub(all) enum MavDistanceSensor {
  Laser
  Ultrasound
  Infrared
  Radar
  Unknown
} derive(Eq, Debug)

///|
pub extend MavDistanceSensor with Eq::{not_equal, equal}

///|
pub extend MavDistanceSensor with @debug.Debug::{to_repr}

///|
/// Convert `MavDistanceSensor` to its raw MAVLink numeric value.
pub fn MavDistanceSensor::to_uint(self : MavDistanceSensor) -> UInt32 {
  match self {
    Laser => 0U
    Ultrasound => 1U
    Infrared => 2U
    Radar => 3U
    Unknown => 4U
  }
}

///|
/// Decode `MavDistanceSensor` from its raw MAVLink numeric value.
pub fn MavDistanceSensor::from_uint(v : UInt32) -> MavDistanceSensor? {
  match v {
    0U => Some(Laser)
    1U => Some(Ultrasound)
    2U => Some(Infrared)
    3U => Some(Radar)
    4U => Some(Unknown)
    _ => None
  }
}

///|
/// Enumeration of sensor orientation, according to its rotations.
pub(all) enum MavSensorOrientation {
  MavSensorRotationNone
  MavSensorRotationYaw45
  MavSensorRotationYaw90
  MavSensorRotationYaw180
  MavSensorRotationYaw270
  MavSensorRotationPitch270
} derive(Eq, Debug)

///|
pub extend MavSensorOrientation with Eq::{not_equal, equal}

///|
pub extend MavSensorOrientation with @debug.Debug::{to_repr}

///|
/// Convert `MavSensorOrientation` to its raw MAVLink numeric value.
pub fn MavSensorOrientation::to_uint(self : MavSensorOrientation) -> UInt32 {
  match self {
    MavSensorRotationNone => 0U
    MavSensorRotationYaw45 => 1U
    MavSensorRotationYaw90 => 2U
    MavSensorRotationYaw180 => 4U
    MavSensorRotationYaw270 => 6U
    MavSensorRotationPitch270 => 25U
  }
}

///|
/// Decode `MavSensorOrientation` from its raw MAVLink numeric value.
pub fn MavSensorOrientation::from_uint(v : UInt32) -> MavSensorOrientation? {
  match v {
    0U => Some(MavSensorRotationNone)
    1U => Some(MavSensorRotationYaw45)
    2U => Some(MavSensorRotationYaw90)
    4U => Some(MavSensorRotationYaw180)
    6U => Some(MavSensorRotationYaw270)
    25U => Some(MavSensorRotationPitch270)
    _ => None
  }
}

///|
/// Enumeration of landed detector states.
pub(all) enum MavLandedState {
  Undefined
  OnGround
  InAir
  Takeoff
  Landing
} derive(Eq, Debug)

///|
pub extend MavLandedState with Eq::{not_equal, equal}

///|
pub extend MavLandedState with @debug.Debug::{to_repr}

///|
/// Convert `MavLandedState` to its raw MAVLink numeric value.
pub fn MavLandedState::to_uint(self : MavLandedState) -> UInt32 {
  match self {
    Undefined => 0U
    OnGround => 1U
    InAir => 2U
    Takeoff => 3U
    Landing => 4U
  }
}

///|
/// Decode `MavLandedState` from its raw MAVLink numeric value.
pub fn MavLandedState::from_uint(v : UInt32) -> MavLandedState? {
  match v {
    0U => Some(Undefined)
    1U => Some(OnGround)
    2U => Some(InAir)
    3U => Some(Takeoff)
    4U => Some(Landing)
    _ => None
  }
}

///|
/// Enumeration of VTOL states.
pub(all) enum MavVtolState {
  Undefined
  TransitionToFw
  TransitionToMc
  Mc
  Fw
} derive(Eq, Debug)

///|
pub extend MavVtolState with Eq::{not_equal, equal}

///|
pub extend MavVtolState with @debug.Debug::{to_repr}

///|
/// Convert `MavVtolState` to its raw MAVLink numeric value.
pub fn MavVtolState::to_uint(self : MavVtolState) -> UInt32 {
  match self {
    Undefined => 0U
    TransitionToFw => 1U
    TransitionToMc => 2U
    Mc => 3U
    Fw => 4U
  }
}

///|
/// Decode `MavVtolState` from its raw MAVLink numeric value.
pub fn MavVtolState::from_uint(v : UInt32) -> MavVtolState? {
  match v {
    0U => Some(Undefined)
    1U => Some(TransitionToFw)
    2U => Some(TransitionToMc)
    3U => Some(Mc)
    4U => Some(Fw)
    _ => None
  }
}

///|
/// Specifies the datatype of a MAVLink extended parameter.
pub(all) enum MavParamExtType {
  Uint8
  Int8
  Uint16
  Int16
  Uint32
  Int32
  Uint64
  Int64
  Real32
  Real64
  Custom
} derive(Eq, Debug)

///|
pub extend MavParamExtType with Eq::{not_equal, equal}

///|
pub extend MavParamExtType with @debug.Debug::{to_repr}

///|
/// Convert `MavParamExtType` to its raw MAVLink numeric value.
pub fn MavParamExtType::to_uint(self : MavParamExtType) -> UInt32 {
  match self {
    Uint8 => 1U
    Int8 => 2U
    Uint16 => 3U
    Int16 => 4U
    Uint32 => 5U
    Int32 => 6U
    Uint64 => 7U
    Int64 => 8U
    Real32 => 9U
    Real64 => 10U
    Custom => 11U
  }
}

///|
/// Decode `MavParamExtType` from its raw MAVLink numeric value.
pub fn MavParamExtType::from_uint(v : UInt32) -> MavParamExtType? {
  match v {
    1U => Some(Uint8)
    2U => Some(Int8)
    3U => Some(Uint16)
    4U => Some(Int16)
    5U => Some(Uint32)
    6U => Some(Int32)
    7U => Some(Uint64)
    8U => Some(Int64)
    9U => Some(Real32)
    10U => Some(Real64)
    11U => Some(Custom)
    _ => None
  }
}

///|
/// Result from a MAVLink extended parameter transaction.
pub(all) enum ParamAck {
  Accepted
  ValueUnsupported
  Failed
  InProgress
} derive(Eq, Debug)

///|
pub extend ParamAck with Eq::{not_equal, equal}

///|
pub extend ParamAck with @debug.Debug::{to_repr}

///|
/// Convert `ParamAck` to its raw MAVLink numeric value.
pub fn ParamAck::to_uint(self : ParamAck) -> UInt32 {
  match self {
    Accepted => 0U
    ValueUnsupported => 1U
    Failed => 2U
    InProgress => 3U
  }
}

///|
/// Decode `ParamAck` from its raw MAVLink numeric value.
pub fn ParamAck::from_uint(v : UInt32) -> ParamAck? {
  match v {
    0U => Some(Accepted)
    1U => Some(ValueUnsupported)
    2U => Some(Failed)
    3U => Some(InProgress)
    _ => None
  }
}

///|
/// Bitmap to indicate which dimensions should be ignored by the vehicle.
pub(all) enum PositionTargetTypemask {
  XIgnore
  YIgnore
  ZIgnore
  VxIgnore
  VyIgnore
  VzIgnore
  AxIgnore
  AyIgnore
  AzIgnore
  ForceSet
  YawIgnore
  YawRateIgnore
} derive(Eq, Debug)

///|
pub extend PositionTargetTypemask with Eq::{not_equal, equal}

///|
pub extend PositionTargetTypemask with @debug.Debug::{to_repr}

///|
/// Convert `PositionTargetTypemask` to its raw MAVLink numeric value.
pub fn PositionTargetTypemask::to_uint(self : PositionTargetTypemask) -> UInt32 {
  match self {
    XIgnore => 1U
    YIgnore => 2U
    ZIgnore => 4U
    VxIgnore => 8U
    VyIgnore => 16U
    VzIgnore => 32U
    AxIgnore => 64U
    AyIgnore => 128U
    AzIgnore => 256U
    ForceSet => 512U
    YawIgnore => 1024U
    YawRateIgnore => 2048U
  }
}

///|
/// Decode `PositionTargetTypemask` from its raw MAVLink numeric value.
pub fn PositionTargetTypemask::from_uint(v : UInt32) -> PositionTargetTypemask? {
  match v {
    1U => Some(XIgnore)
    2U => Some(YIgnore)
    4U => Some(ZIgnore)
    8U => Some(VxIgnore)
    16U => Some(VyIgnore)
    32U => Some(VzIgnore)
    64U => Some(AxIgnore)
    128U => Some(AyIgnore)
    256U => Some(AzIgnore)
    512U => Some(ForceSet)
    1024U => Some(YawIgnore)
    2048U => Some(YawRateIgnore)
    _ => None
  }
}

///|
/// Bitmap to indicate which dimensions should be ignored by the vehicle.
pub(all) enum AttitudeTargetTypemask {
  BodyRollRateIgnore
  BodyPitchRateIgnore
  BodyYawRateIgnore
  ThrottleIgnore
  AttitudeIgnore
} derive(Eq, Debug)

///|
pub extend AttitudeTargetTypemask with Eq::{not_equal, equal}

///|
pub extend AttitudeTargetTypemask with @debug.Debug::{to_repr}

///|
/// Convert `AttitudeTargetTypemask` to its raw MAVLink numeric value.
pub fn AttitudeTargetTypemask::to_uint(self : AttitudeTargetTypemask) -> UInt32 {
  match self {
    BodyRollRateIgnore => 1U
    BodyPitchRateIgnore => 2U
    BodyYawRateIgnore => 4U
    ThrottleIgnore => 64U
    AttitudeIgnore => 128U
  }
}

///|
/// Decode `AttitudeTargetTypemask` from its raw MAVLink numeric value.
pub fn AttitudeTargetTypemask::from_uint(v : UInt32) -> AttitudeTargetTypemask? {
  match v {
    1U => Some(BodyRollRateIgnore)
    2U => Some(BodyPitchRateIgnore)
    4U => Some(BodyYawRateIgnore)
    64U => Some(ThrottleIgnore)
    128U => Some(AttitudeIgnore)
    _ => None
  }
}

///|
/// The heartbeat message shows that a system or component is present and responding.
/// - MAVLink Message `HEARTBEAT` (ID: 0, CRC_EXTRA: 50, base_len: 9B, max_len: 9B)
pub(all) struct Heartbeat {
  mav_type : Byte
  autopilot : Byte
  base_mode : Byte
  custom_mode : UInt32
  system_status : Byte
  mavlink_version : Byte
} derive(Eq, Debug)

///|
pub extend Heartbeat with Eq::{not_equal, equal}

///|
pub extend Heartbeat with @debug.Debug::{to_repr}

///|
pub fn Heartbeat::msg_id() -> UInt32 {
  0U
}

///|
pub fn Heartbeat::crc_extra() -> Byte {
  b'\x32'
}

///|
pub fn Heartbeat::base_payload_len() -> Int32 {
  9
}

///|
pub fn Heartbeat::max_payload_len() -> Int32 {
  9
}

///|
/// Serialize `Heartbeat` into wire-ordered little-endian payload bytes.
pub fn Heartbeat::encode_payload(self : Heartbeat, v2~ : Bool = true) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=9)
  writer_.write_uint32(self.custom_mode)
  writer_.write_uint8(self.mav_type)
  writer_.write_uint8(self.autopilot)
  writer_.write_uint8(self.base_mode)
  writer_.write_uint8(self.system_status)
  writer_.write_uint8(self.mavlink_version)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `Heartbeat` from wire-ordered little-endian payload bytes.
pub fn Heartbeat::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[Heartbeat, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let custom_mode = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let mav_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let autopilot = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let base_mode = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let system_status = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let mavlink_version = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    mav_type,
    autopilot,
    base_mode,
    custom_mode,
    system_status,
    mavlink_version,
  })
}

///|
/// The general system state.
/// - MAVLink Message `SYS_STATUS` (ID: 1, CRC_EXTRA: 124, base_len: 31B, max_len: 31B)
pub(all) struct SysStatus {
  onboard_control_sensors_present : UInt32
  onboard_control_sensors_enabled : UInt32
  onboard_control_sensors_health : UInt32
  load : UInt32
  voltage_battery : UInt32
  current_battery : Int32
  battery_remaining : Int32
  drop_rate_comm : UInt32
  errors_comm : UInt32
  errors_count1 : UInt32
  errors_count2 : UInt32
  errors_count3 : UInt32
  errors_count4 : UInt32
} derive(Eq, Debug)

///|
pub extend SysStatus with Eq::{not_equal, equal}

///|
pub extend SysStatus with @debug.Debug::{to_repr}

///|
pub fn SysStatus::msg_id() -> UInt32 {
  1U
}

///|
pub fn SysStatus::crc_extra() -> Byte {
  b'\x7C'
}

///|
pub fn SysStatus::base_payload_len() -> Int32 {
  31
}

///|
pub fn SysStatus::max_payload_len() -> Int32 {
  31
}

///|
/// Serialize `SysStatus` into wire-ordered little-endian payload bytes.
pub fn SysStatus::encode_payload(self : SysStatus, v2~ : Bool = true) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=31)
  writer_.write_uint32(self.onboard_control_sensors_present)
  writer_.write_uint32(self.onboard_control_sensors_enabled)
  writer_.write_uint32(self.onboard_control_sensors_health)
  writer_.write_uint16(self.load)
  writer_.write_uint16(self.voltage_battery)
  writer_.write_int16(self.current_battery)
  writer_.write_uint16(self.drop_rate_comm)
  writer_.write_uint16(self.errors_comm)
  writer_.write_uint16(self.errors_count1)
  writer_.write_uint16(self.errors_count2)
  writer_.write_uint16(self.errors_count3)
  writer_.write_uint16(self.errors_count4)
  writer_.write_int8(self.battery_remaining)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `SysStatus` from wire-ordered little-endian payload bytes.
pub fn SysStatus::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[SysStatus, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let onboard_control_sensors_present = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let onboard_control_sensors_enabled = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let onboard_control_sensors_health = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let load = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let voltage_battery = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let current_battery = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let drop_rate_comm = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let errors_comm = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let errors_count1 = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let errors_count2 = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let errors_count3 = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let errors_count4 = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let battery_remaining = match reader_.read_int8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    onboard_control_sensors_present,
    onboard_control_sensors_enabled,
    onboard_control_sensors_health,
    load,
    voltage_battery,
    current_battery,
    battery_remaining,
    drop_rate_comm,
    errors_comm,
    errors_count1,
    errors_count2,
    errors_count3,
    errors_count4,
  })
}

///|
/// The system time is the time of the master clock, typically the computer clock of the main onboard computer.
/// - MAVLink Message `SYSTEM_TIME` (ID: 2, CRC_EXTRA: 137, base_len: 12B, max_len: 12B)
pub(all) struct SystemTime {
  time_unix_usec : UInt64
  time_boot_ms : UInt32
} derive(Eq, Debug)

///|
pub extend SystemTime with Eq::{not_equal, equal}

///|
pub extend SystemTime with @debug.Debug::{to_repr}

///|
pub fn SystemTime::msg_id() -> UInt32 {
  2U
}

///|
pub fn SystemTime::crc_extra() -> Byte {
  b'\x89'
}

///|
pub fn SystemTime::base_payload_len() -> Int32 {
  12
}

///|
pub fn SystemTime::max_payload_len() -> Int32 {
  12
}

///|
/// Serialize `SystemTime` into wire-ordered little-endian payload bytes.
pub fn SystemTime::encode_payload(
  self : SystemTime,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=12)
  writer_.write_uint64(self.time_unix_usec)
  writer_.write_uint32(self.time_boot_ms)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `SystemTime` from wire-ordered little-endian payload bytes.
pub fn SystemTime::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[SystemTime, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_unix_usec = match reader_.read_uint64() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let time_boot_ms = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ time_unix_usec, time_boot_ms, })
}

///|
/// A ping message either requesting or responding to a ping.
/// - MAVLink Message `PING` (ID: 4, CRC_EXTRA: 237, base_len: 14B, max_len: 14B)
pub(all) struct Ping {
  time_usec : UInt64
  seq : UInt32
  target_system : Byte
  target_component : Byte
} derive(Eq, Debug)

///|
pub extend Ping with Eq::{not_equal, equal}

///|
pub extend Ping with @debug.Debug::{to_repr}

///|
pub fn Ping::msg_id() -> UInt32 {
  4U
}

///|
pub fn Ping::crc_extra() -> Byte {
  b'\xED'
}

///|
pub fn Ping::base_payload_len() -> Int32 {
  14
}

///|
pub fn Ping::max_payload_len() -> Int32 {
  14
}

///|
/// Serialize `Ping` into wire-ordered little-endian payload bytes.
pub fn Ping::encode_payload(self : Ping, v2~ : Bool = true) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=14)
  writer_.write_uint64(self.time_usec)
  writer_.write_uint32(self.seq)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `Ping` from wire-ordered little-endian payload bytes.
pub fn Ping::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[Ping, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_usec = match reader_.read_uint64() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let seq = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ time_usec, seq, target_system, target_component, })
}

///|
/// Set the system mode, as defined by enum MAV_MODE.
/// - MAVLink Message `SET_MODE` (ID: 11, CRC_EXTRA: 89, base_len: 6B, max_len: 6B)
pub(all) struct SetMode {
  target_system : Byte
  base_mode : Byte
  custom_mode : UInt32
} derive(Eq, Debug)

///|
pub extend SetMode with Eq::{not_equal, equal}

///|
pub extend SetMode with @debug.Debug::{to_repr}

///|
pub fn SetMode::msg_id() -> UInt32 {
  11U
}

///|
pub fn SetMode::crc_extra() -> Byte {
  b'\x59'
}

///|
pub fn SetMode::base_payload_len() -> Int32 {
  6
}

///|
pub fn SetMode::max_payload_len() -> Int32 {
  6
}

///|
/// Serialize `SetMode` into wire-ordered little-endian payload bytes.
pub fn SetMode::encode_payload(self : SetMode, v2~ : Bool = true) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=6)
  writer_.write_uint32(self.custom_mode)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.base_mode)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `SetMode` from wire-ordered little-endian payload bytes.
pub fn SetMode::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[SetMode, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let custom_mode = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let base_mode = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, base_mode, custom_mode, })
}

///|
/// Request to read the onboard parameter with the param_id string id.
/// - MAVLink Message `PARAM_REQUEST_READ` (ID: 20, CRC_EXTRA: 214, base_len: 20B, max_len: 20B)
pub(all) struct ParamRequestRead {
  target_system : Byte
  target_component : Byte
  param_id : String
  param_index : Int32
} derive(Eq, Debug)

///|
pub extend ParamRequestRead with Eq::{not_equal, equal}

///|
pub extend ParamRequestRead with @debug.Debug::{to_repr}

///|
pub fn ParamRequestRead::msg_id() -> UInt32 {
  20U
}

///|
pub fn ParamRequestRead::crc_extra() -> Byte {
  b'\xD6'
}

///|
pub fn ParamRequestRead::base_payload_len() -> Int32 {
  20
}

///|
pub fn ParamRequestRead::max_payload_len() -> Int32 {
  20
}

///|
/// Serialize `ParamRequestRead` into wire-ordered little-endian payload bytes.
pub fn ParamRequestRead::encode_payload(
  self : ParamRequestRead,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=20)
  writer_.write_int16(self.param_index)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.write_char_array(self.param_id, 16)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `ParamRequestRead` from wire-ordered little-endian payload bytes.
pub fn ParamRequestRead::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[ParamRequestRead, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let param_index = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_id = match reader_.read_char_array(16) {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, param_id, param_index, })
}

///|
/// Request all parameters of this component.
/// - MAVLink Message `PARAM_REQUEST_LIST` (ID: 21, CRC_EXTRA: 159, base_len: 2B, max_len: 2B)
pub(all) struct ParamRequestList {
  target_system : Byte
  target_component : Byte
} derive(Eq, Debug)

///|
pub extend ParamRequestList with Eq::{not_equal, equal}

///|
pub extend ParamRequestList with @debug.Debug::{to_repr}

///|
pub fn ParamRequestList::msg_id() -> UInt32 {
  21U
}

///|
pub fn ParamRequestList::crc_extra() -> Byte {
  b'\x9F'
}

///|
pub fn ParamRequestList::base_payload_len() -> Int32 {
  2
}

///|
pub fn ParamRequestList::max_payload_len() -> Int32 {
  2
}

///|
/// Serialize `ParamRequestList` into wire-ordered little-endian payload bytes.
pub fn ParamRequestList::encode_payload(
  self : ParamRequestList,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=2)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `ParamRequestList` from wire-ordered little-endian payload bytes.
pub fn ParamRequestList::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[ParamRequestList, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, })
}

///|
/// Emit the value of a onboard parameter.
/// - MAVLink Message `PARAM_VALUE` (ID: 22, CRC_EXTRA: 220, base_len: 25B, max_len: 25B)
pub(all) struct ParamValue {
  param_id : String
  param_value : Float
  param_type : Byte
  param_count : UInt32
  param_index : UInt32
} derive(Eq, Debug)

///|
pub extend ParamValue with Eq::{not_equal, equal}

///|
pub extend ParamValue with @debug.Debug::{to_repr}

///|
pub fn ParamValue::msg_id() -> UInt32 {
  22U
}

///|
pub fn ParamValue::crc_extra() -> Byte {
  b'\xDC'
}

///|
pub fn ParamValue::base_payload_len() -> Int32 {
  25
}

///|
pub fn ParamValue::max_payload_len() -> Int32 {
  25
}

///|
/// Serialize `ParamValue` into wire-ordered little-endian payload bytes.
pub fn ParamValue::encode_payload(
  self : ParamValue,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=25)
  writer_.write_float(self.param_value)
  writer_.write_uint16(self.param_count)
  writer_.write_uint16(self.param_index)
  writer_.write_char_array(self.param_id, 16)
  writer_.write_uint8(self.param_type)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `ParamValue` from wire-ordered little-endian payload bytes.
pub fn ParamValue::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[ParamValue, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let param_value = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_count = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_index = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_id = match reader_.read_char_array(16) {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ param_id, param_value, param_type, param_count, param_index, })
}

///|
/// Set a parameter value (write new value to permanent storage).
/// - MAVLink Message `PARAM_SET` (ID: 23, CRC_EXTRA: 168, base_len: 23B, max_len: 23B)
pub(all) struct ParamSet {
  target_system : Byte
  target_component : Byte
  param_id : String
  param_value : Float
  param_type : Byte
} derive(Eq, Debug)

///|
pub extend ParamSet with Eq::{not_equal, equal}

///|
pub extend ParamSet with @debug.Debug::{to_repr}

///|
pub fn ParamSet::msg_id() -> UInt32 {
  23U
}

///|
pub fn ParamSet::crc_extra() -> Byte {
  b'\xA8'
}

///|
pub fn ParamSet::base_payload_len() -> Int32 {
  23
}

///|
pub fn ParamSet::max_payload_len() -> Int32 {
  23
}

///|
/// Serialize `ParamSet` into wire-ordered little-endian payload bytes.
pub fn ParamSet::encode_payload(self : ParamSet, v2~ : Bool = true) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=23)
  writer_.write_float(self.param_value)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.write_char_array(self.param_id, 16)
  writer_.write_uint8(self.param_type)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `ParamSet` from wire-ordered little-endian payload bytes.
pub fn ParamSet::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[ParamSet, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let param_value = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_id = match reader_.read_char_array(16) {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, param_id, param_value, param_type, })
}

///|
/// The global position, as returned by the Global Positioning System (GPS).
/// - MAVLink Message `GPS_RAW_INT` (ID: 24, CRC_EXTRA: 24, base_len: 30B, max_len: 52B)
pub(all) struct GpsRawInt {
  time_usec : UInt64
  fix_type : Byte
  lat : Int32
  lon : Int32
  alt : Int32
  eph : UInt32
  epv : UInt32
  vel : UInt32
  cog : UInt32
  satellites_visible : Byte
  alt_ellipsoid : Int32
  h_acc : UInt32
  v_acc : UInt32
  vel_acc : UInt32
  hdg_acc : UInt32
  yaw : UInt32
} derive(Eq, Debug)

///|
pub extend GpsRawInt with Eq::{not_equal, equal}

///|
pub extend GpsRawInt with @debug.Debug::{to_repr}

///|
pub fn GpsRawInt::msg_id() -> UInt32 {
  24U
}

///|
pub fn GpsRawInt::crc_extra() -> Byte {
  b'\x18'
}

///|
pub fn GpsRawInt::base_payload_len() -> Int32 {
  30
}

///|
pub fn GpsRawInt::max_payload_len() -> Int32 {
  52
}

///|
/// Serialize `GpsRawInt` into wire-ordered little-endian payload bytes.
pub fn GpsRawInt::encode_payload(self : GpsRawInt, v2~ : Bool = true) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=52)
  writer_.write_uint64(self.time_usec)
  writer_.write_int32(self.lat)
  writer_.write_int32(self.lon)
  writer_.write_int32(self.alt)
  writer_.write_uint16(self.eph)
  writer_.write_uint16(self.epv)
  writer_.write_uint16(self.vel)
  writer_.write_uint16(self.cog)
  writer_.write_uint8(self.fix_type)
  writer_.write_uint8(self.satellites_visible)
  if v2 {
    writer_.write_int32(self.alt_ellipsoid)
    writer_.write_uint32(self.h_acc)
    writer_.write_uint32(self.v_acc)
    writer_.write_uint32(self.vel_acc)
    writer_.write_uint32(self.hdg_acc)
    writer_.write_uint16(self.yaw)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `GpsRawInt` from wire-ordered little-endian payload bytes.
pub fn GpsRawInt::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[GpsRawInt, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_usec = match reader_.read_uint64() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let lat = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let lon = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let alt = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let eph = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let epv = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vel = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let cog = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let fix_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let satellites_visible = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let alt_ellipsoid = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let h_acc = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let v_acc = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vel_acc = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let hdg_acc = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let yaw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    time_usec,
    fix_type,
    lat,
    lon,
    alt,
    eph,
    epv,
    vel,
    cog,
    satellites_visible,
    alt_ellipsoid,
    h_acc,
    v_acc,
    vel_acc,
    hdg_acc,
    yaw,
  })
}

///|
/// The RAW IMU readings for the usual 9DOF sensor setup (scaled to milli-g / millirad/s).
/// - MAVLink Message `SCALED_IMU` (ID: 26, CRC_EXTRA: 170, base_len: 22B, max_len: 24B)
pub(all) struct ScaledImu {
  time_boot_ms : UInt32
  xacc : Int32
  yacc : Int32
  zacc : Int32
  xgyro : Int32
  ygyro : Int32
  zgyro : Int32
  xmag : Int32
  ymag : Int32
  zmag : Int32
  temperature : Int32
} derive(Eq, Debug)

///|
pub extend ScaledImu with Eq::{not_equal, equal}

///|
pub extend ScaledImu with @debug.Debug::{to_repr}

///|
pub fn ScaledImu::msg_id() -> UInt32 {
  26U
}

///|
pub fn ScaledImu::crc_extra() -> Byte {
  b'\xAA'
}

///|
pub fn ScaledImu::base_payload_len() -> Int32 {
  22
}

///|
pub fn ScaledImu::max_payload_len() -> Int32 {
  24
}

///|
/// Serialize `ScaledImu` into wire-ordered little-endian payload bytes.
pub fn ScaledImu::encode_payload(self : ScaledImu, v2~ : Bool = true) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=24)
  writer_.write_uint32(self.time_boot_ms)
  writer_.write_int16(self.xacc)
  writer_.write_int16(self.yacc)
  writer_.write_int16(self.zacc)
  writer_.write_int16(self.xgyro)
  writer_.write_int16(self.ygyro)
  writer_.write_int16(self.zgyro)
  writer_.write_int16(self.xmag)
  writer_.write_int16(self.ymag)
  writer_.write_int16(self.zmag)
  if v2 {
    writer_.write_int16(self.temperature)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `ScaledImu` from wire-ordered little-endian payload bytes.
pub fn ScaledImu::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[ScaledImu, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_boot_ms = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let xacc = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let yacc = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let zacc = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let xgyro = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let ygyro = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let zgyro = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let xmag = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let ymag = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let zmag = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let temperature = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    time_boot_ms,
    xacc,
    yacc,
    zacc,
    xgyro,
    ygyro,
    zgyro,
    xmag,
    ymag,
    zmag,
    temperature,
  })
}

///|
/// The RAW IMU readings for a 9DOF sensor, which is identified by the id (default IMU1).
/// - MAVLink Message `RAW_IMU` (ID: 27, CRC_EXTRA: 144, base_len: 26B, max_len: 29B)
pub(all) struct RawImu {
  time_usec : UInt64
  xacc : Int32
  yacc : Int32
  zacc : Int32
  xgyro : Int32
  ygyro : Int32
  zgyro : Int32
  xmag : Int32
  ymag : Int32
  zmag : Int32
  id : Byte
  temperature : Int32
} derive(Eq, Debug)

///|
pub extend RawImu with Eq::{not_equal, equal}

///|
pub extend RawImu with @debug.Debug::{to_repr}

///|
pub fn RawImu::msg_id() -> UInt32 {
  27U
}

///|
pub fn RawImu::crc_extra() -> Byte {
  b'\x90'
}

///|
pub fn RawImu::base_payload_len() -> Int32 {
  26
}

///|
pub fn RawImu::max_payload_len() -> Int32 {
  29
}

///|
/// Serialize `RawImu` into wire-ordered little-endian payload bytes.
pub fn RawImu::encode_payload(self : RawImu, v2~ : Bool = true) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=29)
  writer_.write_uint64(self.time_usec)
  writer_.write_int16(self.xacc)
  writer_.write_int16(self.yacc)
  writer_.write_int16(self.zacc)
  writer_.write_int16(self.xgyro)
  writer_.write_int16(self.ygyro)
  writer_.write_int16(self.zgyro)
  writer_.write_int16(self.xmag)
  writer_.write_int16(self.ymag)
  writer_.write_int16(self.zmag)
  if v2 {
    writer_.write_uint8(self.id)
    writer_.write_int16(self.temperature)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `RawImu` from wire-ordered little-endian payload bytes.
pub fn RawImu::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[RawImu, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_usec = match reader_.read_uint64() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let xacc = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let yacc = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let zacc = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let xgyro = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let ygyro = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let zgyro = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let xmag = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let ymag = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let zmag = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let id = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let temperature = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    time_usec,
    xacc,
    yacc,
    zacc,
    xgyro,
    ygyro,
    zgyro,
    xmag,
    ymag,
    zmag,
    id,
    temperature,
  })
}

///|
/// The pressure readings for the typical setup of one absolute and differential pressure sensor.
/// - MAVLink Message `SCALED_PRESSURE` (ID: 29, CRC_EXTRA: 115, base_len: 14B, max_len: 16B)
pub(all) struct ScaledPressure {
  time_boot_ms : UInt32
  press_abs : Float
  press_diff : Float
  temperature : Int32
  temperature_press_diff : Int32
} derive(Eq, Debug)

///|
pub extend ScaledPressure with Eq::{not_equal, equal}

///|
pub extend ScaledPressure with @debug.Debug::{to_repr}

///|
pub fn ScaledPressure::msg_id() -> UInt32 {
  29U
}

///|
pub fn ScaledPressure::crc_extra() -> Byte {
  b'\x73'
}

///|
pub fn ScaledPressure::base_payload_len() -> Int32 {
  14
}

///|
pub fn ScaledPressure::max_payload_len() -> Int32 {
  16
}

///|
/// Serialize `ScaledPressure` into wire-ordered little-endian payload bytes.
pub fn ScaledPressure::encode_payload(
  self : ScaledPressure,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=16)
  writer_.write_uint32(self.time_boot_ms)
  writer_.write_float(self.press_abs)
  writer_.write_float(self.press_diff)
  writer_.write_int16(self.temperature)
  if v2 {
    writer_.write_int16(self.temperature_press_diff)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `ScaledPressure` from wire-ordered little-endian payload bytes.
pub fn ScaledPressure::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[ScaledPressure, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_boot_ms = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let press_abs = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let press_diff = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let temperature = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let temperature_press_diff = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    time_boot_ms,
    press_abs,
    press_diff,
    temperature,
    temperature_press_diff,
  })
}

///|
/// The attitude in the aeronautical frame (right-handed, Z-down, X-front, Y-right).
/// - MAVLink Message `ATTITUDE` (ID: 30, CRC_EXTRA: 39, base_len: 28B, max_len: 28B)
pub(all) struct Attitude {
  time_boot_ms : UInt32
  roll : Float
  pitch : Float
  yaw : Float
  rollspeed : Float
  pitchspeed : Float
  yawspeed : Float
} derive(Eq, Debug)

///|
pub extend Attitude with Eq::{not_equal, equal}

///|
pub extend Attitude with @debug.Debug::{to_repr}

///|
pub fn Attitude::msg_id() -> UInt32 {
  30U
}

///|
pub fn Attitude::crc_extra() -> Byte {
  b'\x27'
}

///|
pub fn Attitude::base_payload_len() -> Int32 {
  28
}

///|
pub fn Attitude::max_payload_len() -> Int32 {
  28
}

///|
/// Serialize `Attitude` into wire-ordered little-endian payload bytes.
pub fn Attitude::encode_payload(self : Attitude, v2~ : Bool = true) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=28)
  writer_.write_uint32(self.time_boot_ms)
  writer_.write_float(self.roll)
  writer_.write_float(self.pitch)
  writer_.write_float(self.yaw)
  writer_.write_float(self.rollspeed)
  writer_.write_float(self.pitchspeed)
  writer_.write_float(self.yawspeed)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `Attitude` from wire-ordered little-endian payload bytes.
pub fn Attitude::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[Attitude, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_boot_ms = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let roll = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let pitch = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let yaw = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let rollspeed = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let pitchspeed = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let yawspeed = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ time_boot_ms, roll, pitch, yaw, rollspeed, pitchspeed, yawspeed, })
}

///|
/// The attitude in the aeronautical frame (right-handed, Z-down, X-front, Y-right), expressed as quaternion.
/// - MAVLink Message `ATTITUDE_QUATERNION` (ID: 31, CRC_EXTRA: 246, base_len: 32B, max_len: 48B)
pub(all) struct AttitudeQuaternion {
  time_boot_ms : UInt32
  q1 : Float
  q2 : Float
  q3 : Float
  q4 : Float
  rollspeed : Float
  pitchspeed : Float
  yawspeed : Float
  repr_offset_q : FixedArray[Float]
} derive(Eq, Debug)

///|
pub extend AttitudeQuaternion with Eq::{not_equal, equal}

///|
pub extend AttitudeQuaternion with @debug.Debug::{to_repr}

///|
pub fn AttitudeQuaternion::msg_id() -> UInt32 {
  31U
}

///|
pub fn AttitudeQuaternion::crc_extra() -> Byte {
  b'\xF6'
}

///|
pub fn AttitudeQuaternion::base_payload_len() -> Int32 {
  32
}

///|
pub fn AttitudeQuaternion::max_payload_len() -> Int32 {
  48
}

///|
/// Serialize `AttitudeQuaternion` into wire-ordered little-endian payload bytes.
pub fn AttitudeQuaternion::encode_payload(
  self : AttitudeQuaternion,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=48)
  writer_.write_uint32(self.time_boot_ms)
  writer_.write_float(self.q1)
  writer_.write_float(self.q2)
  writer_.write_float(self.q3)
  writer_.write_float(self.q4)
  writer_.write_float(self.rollspeed)
  writer_.write_float(self.pitchspeed)
  writer_.write_float(self.yawspeed)
  if v2 {
    for idx_ = 0; idx_ < 4; idx_ = idx_ + 1 {
      let elem_ = if idx_ < self.repr_offset_q.length() {
        self.repr_offset_q[idx_]
      } else {
        (0.0 : Float)
      }
      writer_.write_float(elem_)
    }
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `AttitudeQuaternion` from wire-ordered little-endian payload bytes.
pub fn AttitudeQuaternion::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[AttitudeQuaternion, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_boot_ms = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let q1 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let q2 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let q3 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let q4 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let rollspeed = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let pitchspeed = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let yawspeed = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let repr_offset_q = FixedArray::make(4, (0.0 : Float))
  for idx_ = 0; idx_ < 4; idx_ = idx_ + 1 {
    match reader_.read_float() {
      Ok(v) => repr_offset_q[idx_] = v
      Err(e) => return Err(e)
    }
  }
  Ok({
    time_boot_ms,
    q1,
    q2,
    q3,
    q4,
    rollspeed,
    pitchspeed,
    yawspeed,
    repr_offset_q,
  })
}

///|
/// The filtered local position (e.g. fused computer vision and accelerometers) in NED frame.
/// - MAVLink Message `LOCAL_POSITION_NED` (ID: 32, CRC_EXTRA: 185, base_len: 28B, max_len: 28B)
pub(all) struct LocalPositionNed {
  time_boot_ms : UInt32
  x : Float
  y : Float
  z : Float
  vx : Float
  vy : Float
  vz : Float
} derive(Eq, Debug)

///|
pub extend LocalPositionNed with Eq::{not_equal, equal}

///|
pub extend LocalPositionNed with @debug.Debug::{to_repr}

///|
pub fn LocalPositionNed::msg_id() -> UInt32 {
  32U
}

///|
pub fn LocalPositionNed::crc_extra() -> Byte {
  b'\xB9'
}

///|
pub fn LocalPositionNed::base_payload_len() -> Int32 {
  28
}

///|
pub fn LocalPositionNed::max_payload_len() -> Int32 {
  28
}

///|
/// Serialize `LocalPositionNed` into wire-ordered little-endian payload bytes.
pub fn LocalPositionNed::encode_payload(
  self : LocalPositionNed,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=28)
  writer_.write_uint32(self.time_boot_ms)
  writer_.write_float(self.x)
  writer_.write_float(self.y)
  writer_.write_float(self.z)
  writer_.write_float(self.vx)
  writer_.write_float(self.vy)
  writer_.write_float(self.vz)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `LocalPositionNed` from wire-ordered little-endian payload bytes.
pub fn LocalPositionNed::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[LocalPositionNed, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_boot_ms = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let x = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let y = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let z = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vx = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vy = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vz = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ time_boot_ms, x, y, z, vx, vy, vz, })
}

///|
/// The filtered global position (e.g. fused GPS and accelerometers).
/// - MAVLink Message `GLOBAL_POSITION_INT` (ID: 33, CRC_EXTRA: 104, base_len: 28B, max_len: 28B)
pub(all) struct GlobalPositionInt {
  time_boot_ms : UInt32
  lat : Int32
  lon : Int32
  alt : Int32
  relative_alt : Int32
  vx : Int32
  vy : Int32
  vz : Int32
  hdg : UInt32
} derive(Eq, Debug)

///|
pub extend GlobalPositionInt with Eq::{not_equal, equal}

///|
pub extend GlobalPositionInt with @debug.Debug::{to_repr}

///|
pub fn GlobalPositionInt::msg_id() -> UInt32 {
  33U
}

///|
pub fn GlobalPositionInt::crc_extra() -> Byte {
  b'\x68'
}

///|
pub fn GlobalPositionInt::base_payload_len() -> Int32 {
  28
}

///|
pub fn GlobalPositionInt::max_payload_len() -> Int32 {
  28
}

///|
/// Serialize `GlobalPositionInt` into wire-ordered little-endian payload bytes.
pub fn GlobalPositionInt::encode_payload(
  self : GlobalPositionInt,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=28)
  writer_.write_uint32(self.time_boot_ms)
  writer_.write_int32(self.lat)
  writer_.write_int32(self.lon)
  writer_.write_int32(self.alt)
  writer_.write_int32(self.relative_alt)
  writer_.write_int16(self.vx)
  writer_.write_int16(self.vy)
  writer_.write_int16(self.vz)
  writer_.write_uint16(self.hdg)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `GlobalPositionInt` from wire-ordered little-endian payload bytes.
pub fn GlobalPositionInt::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[GlobalPositionInt, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_boot_ms = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let lat = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let lon = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let alt = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let relative_alt = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vx = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vy = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vz = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let hdg = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ time_boot_ms, lat, lon, alt, relative_alt, vx, vy, vz, hdg, })
}

///|
/// The RAW values of the RC channels received.
/// - MAVLink Message `RC_CHANNELS_RAW` (ID: 35, CRC_EXTRA: 244, base_len: 22B, max_len: 22B)
pub(all) struct RcChannelsRaw {
  time_boot_ms : UInt32
  port : Byte
  chan1_raw : UInt32
  chan2_raw : UInt32
  chan3_raw : UInt32
  chan4_raw : UInt32
  chan5_raw : UInt32
  chan6_raw : UInt32
  chan7_raw : UInt32
  chan8_raw : UInt32
  rssi : Byte
} derive(Eq, Debug)

///|
pub extend RcChannelsRaw with Eq::{not_equal, equal}

///|
pub extend RcChannelsRaw with @debug.Debug::{to_repr}

///|
pub fn RcChannelsRaw::msg_id() -> UInt32 {
  35U
}

///|
pub fn RcChannelsRaw::crc_extra() -> Byte {
  b'\xF4'
}

///|
pub fn RcChannelsRaw::base_payload_len() -> Int32 {
  22
}

///|
pub fn RcChannelsRaw::max_payload_len() -> Int32 {
  22
}

///|
/// Serialize `RcChannelsRaw` into wire-ordered little-endian payload bytes.
pub fn RcChannelsRaw::encode_payload(
  self : RcChannelsRaw,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=22)
  writer_.write_uint32(self.time_boot_ms)
  writer_.write_uint16(self.chan1_raw)
  writer_.write_uint16(self.chan2_raw)
  writer_.write_uint16(self.chan3_raw)
  writer_.write_uint16(self.chan4_raw)
  writer_.write_uint16(self.chan5_raw)
  writer_.write_uint16(self.chan6_raw)
  writer_.write_uint16(self.chan7_raw)
  writer_.write_uint16(self.chan8_raw)
  writer_.write_uint8(self.port)
  writer_.write_uint8(self.rssi)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `RcChannelsRaw` from wire-ordered little-endian payload bytes.
pub fn RcChannelsRaw::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[RcChannelsRaw, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_boot_ms = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan1_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan2_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan3_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan4_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan5_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan6_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan7_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan8_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let port = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let rssi = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    time_boot_ms,
    port,
    chan1_raw,
    chan2_raw,
    chan3_raw,
    chan4_raw,
    chan5_raw,
    chan6_raw,
    chan7_raw,
    chan8_raw,
    rssi,
  })
}

///|
/// The RAW values of the servo outputs (for RC input from the remote, use the RC_CHANNELS messages).
/// - MAVLink Message `SERVO_OUTPUT_RAW` (ID: 36, CRC_EXTRA: 222, base_len: 21B, max_len: 37B)
pub(all) struct ServoOutputRaw {
  time_usec : UInt32
  port : Byte
  servo1_raw : UInt32
  servo2_raw : UInt32
  servo3_raw : UInt32
  servo4_raw : UInt32
  servo5_raw : UInt32
  servo6_raw : UInt32
  servo7_raw : UInt32
  servo8_raw : UInt32
  servo9_raw : UInt32
  servo10_raw : UInt32
  servo11_raw : UInt32
  servo12_raw : UInt32
  servo13_raw : UInt32
  servo14_raw : UInt32
  servo15_raw : UInt32
  servo16_raw : UInt32
} derive(Eq, Debug)

///|
pub extend ServoOutputRaw with Eq::{not_equal, equal}

///|
pub extend ServoOutputRaw with @debug.Debug::{to_repr}

///|
pub fn ServoOutputRaw::msg_id() -> UInt32 {
  36U
}

///|
pub fn ServoOutputRaw::crc_extra() -> Byte {
  b'\xDE'
}

///|
pub fn ServoOutputRaw::base_payload_len() -> Int32 {
  21
}

///|
pub fn ServoOutputRaw::max_payload_len() -> Int32 {
  37
}

///|
/// Serialize `ServoOutputRaw` into wire-ordered little-endian payload bytes.
pub fn ServoOutputRaw::encode_payload(
  self : ServoOutputRaw,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=37)
  writer_.write_uint32(self.time_usec)
  writer_.write_uint16(self.servo1_raw)
  writer_.write_uint16(self.servo2_raw)
  writer_.write_uint16(self.servo3_raw)
  writer_.write_uint16(self.servo4_raw)
  writer_.write_uint16(self.servo5_raw)
  writer_.write_uint16(self.servo6_raw)
  writer_.write_uint16(self.servo7_raw)
  writer_.write_uint16(self.servo8_raw)
  writer_.write_uint8(self.port)
  if v2 {
    writer_.write_uint16(self.servo9_raw)
    writer_.write_uint16(self.servo10_raw)
    writer_.write_uint16(self.servo11_raw)
    writer_.write_uint16(self.servo12_raw)
    writer_.write_uint16(self.servo13_raw)
    writer_.write_uint16(self.servo14_raw)
    writer_.write_uint16(self.servo15_raw)
    writer_.write_uint16(self.servo16_raw)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `ServoOutputRaw` from wire-ordered little-endian payload bytes.
pub fn ServoOutputRaw::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[ServoOutputRaw, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_usec = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let servo1_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let servo2_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let servo3_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let servo4_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let servo5_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let servo6_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let servo7_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let servo8_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let port = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let servo9_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let servo10_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let servo11_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let servo12_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let servo13_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let servo14_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let servo15_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let servo16_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    time_usec,
    port,
    servo1_raw,
    servo2_raw,
    servo3_raw,
    servo4_raw,
    servo5_raw,
    servo6_raw,
    servo7_raw,
    servo8_raw,
    servo9_raw,
    servo10_raw,
    servo11_raw,
    servo12_raw,
    servo13_raw,
    servo14_raw,
    servo15_raw,
    servo16_raw,
  })
}

///|
/// Request the information of the mission item with the sequence number seq.
/// - MAVLink Message `MISSION_REQUEST` (ID: 40, CRC_EXTRA: 230, base_len: 4B, max_len: 5B)
pub(all) struct MissionRequest {
  target_system : Byte
  target_component : Byte
  seq : UInt32
  mission_type : Byte
} derive(Eq, Debug)

///|
pub extend MissionRequest with Eq::{not_equal, equal}

///|
pub extend MissionRequest with @debug.Debug::{to_repr}

///|
pub fn MissionRequest::msg_id() -> UInt32 {
  40U
}

///|
pub fn MissionRequest::crc_extra() -> Byte {
  b'\xE6'
}

///|
pub fn MissionRequest::base_payload_len() -> Int32 {
  4
}

///|
pub fn MissionRequest::max_payload_len() -> Int32 {
  5
}

///|
/// Serialize `MissionRequest` into wire-ordered little-endian payload bytes.
pub fn MissionRequest::encode_payload(
  self : MissionRequest,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=5)
  writer_.write_uint16(self.seq)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  if v2 {
    writer_.write_uint8(self.mission_type)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `MissionRequest` from wire-ordered little-endian payload bytes.
pub fn MissionRequest::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[MissionRequest, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let seq = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let mission_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, seq, mission_type, })
}

///|
/// Set the mission item with sequence number seq as current item.
/// - MAVLink Message `MISSION_SET_CURRENT` (ID: 41, CRC_EXTRA: 28, base_len: 4B, max_len: 4B)
pub(all) struct MissionSetCurrent {
  target_system : Byte
  target_component : Byte
  seq : UInt32
} derive(Eq, Debug)

///|
pub extend MissionSetCurrent with Eq::{not_equal, equal}

///|
pub extend MissionSetCurrent with @debug.Debug::{to_repr}

///|
pub fn MissionSetCurrent::msg_id() -> UInt32 {
  41U
}

///|
pub fn MissionSetCurrent::crc_extra() -> Byte {
  b'\x1C'
}

///|
pub fn MissionSetCurrent::base_payload_len() -> Int32 {
  4
}

///|
pub fn MissionSetCurrent::max_payload_len() -> Int32 {
  4
}

///|
/// Serialize `MissionSetCurrent` into wire-ordered little-endian payload bytes.
pub fn MissionSetCurrent::encode_payload(
  self : MissionSetCurrent,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=4)
  writer_.write_uint16(self.seq)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `MissionSetCurrent` from wire-ordered little-endian payload bytes.
pub fn MissionSetCurrent::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[MissionSetCurrent, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let seq = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, seq, })
}

///|
/// Message that announces the sequence number of the current active mission item.
/// - MAVLink Message `MISSION_CURRENT` (ID: 42, CRC_EXTRA: 28, base_len: 2B, max_len: 6B)
pub(all) struct MissionCurrent {
  seq : UInt32
  total : UInt32
  mission_state : Byte
  mission_mode : Byte
} derive(Eq, Debug)

///|
pub extend MissionCurrent with Eq::{not_equal, equal}

///|
pub extend MissionCurrent with @debug.Debug::{to_repr}

///|
pub fn MissionCurrent::msg_id() -> UInt32 {
  42U
}

///|
pub fn MissionCurrent::crc_extra() -> Byte {
  b'\x1C'
}

///|
pub fn MissionCurrent::base_payload_len() -> Int32 {
  2
}

///|
pub fn MissionCurrent::max_payload_len() -> Int32 {
  6
}

///|
/// Serialize `MissionCurrent` into wire-ordered little-endian payload bytes.
pub fn MissionCurrent::encode_payload(
  self : MissionCurrent,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=6)
  writer_.write_uint16(self.seq)
  if v2 {
    writer_.write_uint16(self.total)
    writer_.write_uint8(self.mission_state)
    writer_.write_uint8(self.mission_mode)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `MissionCurrent` from wire-ordered little-endian payload bytes.
pub fn MissionCurrent::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[MissionCurrent, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let seq = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let total = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let mission_state = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let mission_mode = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ seq, total, mission_state, mission_mode, })
}

///|
/// Request the overall list of mission items from the system/component.
/// - MAVLink Message `MISSION_REQUEST_LIST` (ID: 43, CRC_EXTRA: 132, base_len: 2B, max_len: 3B)
pub(all) struct MissionRequestList {
  target_system : Byte
  target_component : Byte
  mission_type : Byte
} derive(Eq, Debug)

///|
pub extend MissionRequestList with Eq::{not_equal, equal}

///|
pub extend MissionRequestList with @debug.Debug::{to_repr}

///|
pub fn MissionRequestList::msg_id() -> UInt32 {
  43U
}

///|
pub fn MissionRequestList::crc_extra() -> Byte {
  b'\x84'
}

///|
pub fn MissionRequestList::base_payload_len() -> Int32 {
  2
}

///|
pub fn MissionRequestList::max_payload_len() -> Int32 {
  3
}

///|
/// Serialize `MissionRequestList` into wire-ordered little-endian payload bytes.
pub fn MissionRequestList::encode_payload(
  self : MissionRequestList,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=3)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  if v2 {
    writer_.write_uint8(self.mission_type)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `MissionRequestList` from wire-ordered little-endian payload bytes.
pub fn MissionRequestList::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[MissionRequestList, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let mission_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, mission_type, })
}

///|
/// This message is emitted as response to MISSION_REQUEST_LIST by the MAV and to initiate a write transaction.
/// - MAVLink Message `MISSION_COUNT` (ID: 44, CRC_EXTRA: 221, base_len: 4B, max_len: 9B)
pub(all) struct MissionCount {
  target_system : Byte
  target_component : Byte
  count : UInt32
  mission_type : Byte
  opaque_id : UInt32
} derive(Eq, Debug)

///|
pub extend MissionCount with Eq::{not_equal, equal}

///|
pub extend MissionCount with @debug.Debug::{to_repr}

///|
pub fn MissionCount::msg_id() -> UInt32 {
  44U
}

///|
pub fn MissionCount::crc_extra() -> Byte {
  b'\xDD'
}

///|
pub fn MissionCount::base_payload_len() -> Int32 {
  4
}

///|
pub fn MissionCount::max_payload_len() -> Int32 {
  9
}

///|
/// Serialize `MissionCount` into wire-ordered little-endian payload bytes.
pub fn MissionCount::encode_payload(
  self : MissionCount,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=9)
  writer_.write_uint16(self.count)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  if v2 {
    writer_.write_uint8(self.mission_type)
    writer_.write_uint32(self.opaque_id)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `MissionCount` from wire-ordered little-endian payload bytes.
pub fn MissionCount::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[MissionCount, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let count = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let mission_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let opaque_id = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, count, mission_type, opaque_id, })
}

///|
/// Delete all mission items at once.
/// - MAVLink Message `MISSION_CLEAR_ALL` (ID: 45, CRC_EXTRA: 232, base_len: 2B, max_len: 3B)
pub(all) struct MissionClearAll {
  target_system : Byte
  target_component : Byte
  mission_type : Byte
} derive(Eq, Debug)

///|
pub extend MissionClearAll with Eq::{not_equal, equal}

///|
pub extend MissionClearAll with @debug.Debug::{to_repr}

///|
pub fn MissionClearAll::msg_id() -> UInt32 {
  45U
}

///|
pub fn MissionClearAll::crc_extra() -> Byte {
  b'\xE8'
}

///|
pub fn MissionClearAll::base_payload_len() -> Int32 {
  2
}

///|
pub fn MissionClearAll::max_payload_len() -> Int32 {
  3
}

///|
/// Serialize `MissionClearAll` into wire-ordered little-endian payload bytes.
pub fn MissionClearAll::encode_payload(
  self : MissionClearAll,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=3)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  if v2 {
    writer_.write_uint8(self.mission_type)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `MissionClearAll` from wire-ordered little-endian payload bytes.
pub fn MissionClearAll::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[MissionClearAll, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let mission_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, mission_type, })
}

///|
/// A certain mission item has been reached.
/// - MAVLink Message `MISSION_ITEM_REACHED` (ID: 46, CRC_EXTRA: 11, base_len: 2B, max_len: 2B)
pub(all) struct MissionItemReached {
  seq : UInt32
} derive(Eq, Debug)

///|
pub extend MissionItemReached with Eq::{not_equal, equal}

///|
pub extend MissionItemReached with @debug.Debug::{to_repr}

///|
pub fn MissionItemReached::msg_id() -> UInt32 {
  46U
}

///|
pub fn MissionItemReached::crc_extra() -> Byte {
  b'\x0B'
}

///|
pub fn MissionItemReached::base_payload_len() -> Int32 {
  2
}

///|
pub fn MissionItemReached::max_payload_len() -> Int32 {
  2
}

///|
/// Serialize `MissionItemReached` into wire-ordered little-endian payload bytes.
pub fn MissionItemReached::encode_payload(
  self : MissionItemReached,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=2)
  writer_.write_uint16(self.seq)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `MissionItemReached` from wire-ordered little-endian payload bytes.
pub fn MissionItemReached::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[MissionItemReached, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let seq = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ seq, })
}

///|
/// Acknowledgment message during waypoint handling.
/// - MAVLink Message `MISSION_ACK` (ID: 47, CRC_EXTRA: 153, base_len: 3B, max_len: 8B)
pub(all) struct MissionAck {
  target_system : Byte
  target_component : Byte
  mav_type : Byte
  mission_type : Byte
  opaque_id : UInt32
} derive(Eq, Debug)

///|
pub extend MissionAck with Eq::{not_equal, equal}

///|
pub extend MissionAck with @debug.Debug::{to_repr}

///|
pub fn MissionAck::msg_id() -> UInt32 {
  47U
}

///|
pub fn MissionAck::crc_extra() -> Byte {
  b'\x99'
}

///|
pub fn MissionAck::base_payload_len() -> Int32 {
  3
}

///|
pub fn MissionAck::max_payload_len() -> Int32 {
  8
}

///|
/// Serialize `MissionAck` into wire-ordered little-endian payload bytes.
pub fn MissionAck::encode_payload(
  self : MissionAck,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=8)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.write_uint8(self.mav_type)
  if v2 {
    writer_.write_uint8(self.mission_type)
    writer_.write_uint32(self.opaque_id)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `MissionAck` from wire-ordered little-endian payload bytes.
pub fn MissionAck::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[MissionAck, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let mav_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let mission_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let opaque_id = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, mav_type, mission_type, opaque_id, })
}

///|
/// Request the information of the mission item with the sequence number seq.
/// - MAVLink Message `MISSION_REQUEST_INT` (ID: 51, CRC_EXTRA: 196, base_len: 4B, max_len: 5B)
pub(all) struct MissionRequestInt {
  target_system : Byte
  target_component : Byte
  seq : UInt32
  mission_type : Byte
} derive(Eq, Debug)

///|
pub extend MissionRequestInt with Eq::{not_equal, equal}

///|
pub extend MissionRequestInt with @debug.Debug::{to_repr}

///|
pub fn MissionRequestInt::msg_id() -> UInt32 {
  51U
}

///|
pub fn MissionRequestInt::crc_extra() -> Byte {
  b'\xC4'
}

///|
pub fn MissionRequestInt::base_payload_len() -> Int32 {
  4
}

///|
pub fn MissionRequestInt::max_payload_len() -> Int32 {
  5
}

///|
/// Serialize `MissionRequestInt` into wire-ordered little-endian payload bytes.
pub fn MissionRequestInt::encode_payload(
  self : MissionRequestInt,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=5)
  writer_.write_uint16(self.seq)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  if v2 {
    writer_.write_uint8(self.mission_type)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `MissionRequestInt` from wire-ordered little-endian payload bytes.
pub fn MissionRequestInt::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[MissionRequestInt, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let seq = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let mission_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, seq, mission_type, })
}

///|
/// The PPM values of the RC channels received.
/// - MAVLink Message `RC_CHANNELS` (ID: 65, CRC_EXTRA: 118, base_len: 42B, max_len: 42B)
pub(all) struct RcChannels {
  time_boot_ms : UInt32
  chancount : Byte
  chan1_raw : UInt32
  chan2_raw : UInt32
  chan3_raw : UInt32
  chan4_raw : UInt32
  chan5_raw : UInt32
  chan6_raw : UInt32
  chan7_raw : UInt32
  chan8_raw : UInt32
  chan9_raw : UInt32
  chan10_raw : UInt32
  chan11_raw : UInt32
  chan12_raw : UInt32
  chan13_raw : UInt32
  chan14_raw : UInt32
  chan15_raw : UInt32
  chan16_raw : UInt32
  chan17_raw : UInt32
  chan18_raw : UInt32
  rssi : Byte
} derive(Eq, Debug)

///|
pub extend RcChannels with Eq::{not_equal, equal}

///|
pub extend RcChannels with @debug.Debug::{to_repr}

///|
pub fn RcChannels::msg_id() -> UInt32 {
  65U
}

///|
pub fn RcChannels::crc_extra() -> Byte {
  b'\x76'
}

///|
pub fn RcChannels::base_payload_len() -> Int32 {
  42
}

///|
pub fn RcChannels::max_payload_len() -> Int32 {
  42
}

///|
/// Serialize `RcChannels` into wire-ordered little-endian payload bytes.
pub fn RcChannels::encode_payload(
  self : RcChannels,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=42)
  writer_.write_uint32(self.time_boot_ms)
  writer_.write_uint16(self.chan1_raw)
  writer_.write_uint16(self.chan2_raw)
  writer_.write_uint16(self.chan3_raw)
  writer_.write_uint16(self.chan4_raw)
  writer_.write_uint16(self.chan5_raw)
  writer_.write_uint16(self.chan6_raw)
  writer_.write_uint16(self.chan7_raw)
  writer_.write_uint16(self.chan8_raw)
  writer_.write_uint16(self.chan9_raw)
  writer_.write_uint16(self.chan10_raw)
  writer_.write_uint16(self.chan11_raw)
  writer_.write_uint16(self.chan12_raw)
  writer_.write_uint16(self.chan13_raw)
  writer_.write_uint16(self.chan14_raw)
  writer_.write_uint16(self.chan15_raw)
  writer_.write_uint16(self.chan16_raw)
  writer_.write_uint16(self.chan17_raw)
  writer_.write_uint16(self.chan18_raw)
  writer_.write_uint8(self.chancount)
  writer_.write_uint8(self.rssi)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `RcChannels` from wire-ordered little-endian payload bytes.
pub fn RcChannels::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[RcChannels, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_boot_ms = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan1_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan2_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan3_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan4_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan5_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan6_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan7_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan8_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan9_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan10_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan11_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan12_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan13_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan14_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan15_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan16_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan17_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chan18_raw = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chancount = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let rssi = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    time_boot_ms,
    chancount,
    chan1_raw,
    chan2_raw,
    chan3_raw,
    chan4_raw,
    chan5_raw,
    chan6_raw,
    chan7_raw,
    chan8_raw,
    chan9_raw,
    chan10_raw,
    chan11_raw,
    chan12_raw,
    chan13_raw,
    chan14_raw,
    chan15_raw,
    chan16_raw,
    chan17_raw,
    chan18_raw,
    rssi,
  })
}

///|
/// This message provides an API for manually controlling the vehicle using standard joystick axes.
/// - MAVLink Message `MANUAL_CONTROL` (ID: 69, CRC_EXTRA: 243, base_len: 11B, max_len: 18B)
pub(all) struct ManualControl {
  target : Byte
  x : Int32
  y : Int32
  z : Int32
  r : Int32
  buttons : UInt32
  buttons2 : UInt32
  enabled_extensions : Byte
  s : Int32
  t : Int32
} derive(Eq, Debug)

///|
pub extend ManualControl with Eq::{not_equal, equal}

///|
pub extend ManualControl with @debug.Debug::{to_repr}

///|
pub fn ManualControl::msg_id() -> UInt32 {
  69U
}

///|
pub fn ManualControl::crc_extra() -> Byte {
  b'\xF3'
}

///|
pub fn ManualControl::base_payload_len() -> Int32 {
  11
}

///|
pub fn ManualControl::max_payload_len() -> Int32 {
  18
}

///|
/// Serialize `ManualControl` into wire-ordered little-endian payload bytes.
pub fn ManualControl::encode_payload(
  self : ManualControl,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=18)
  writer_.write_int16(self.x)
  writer_.write_int16(self.y)
  writer_.write_int16(self.z)
  writer_.write_int16(self.r)
  writer_.write_uint16(self.buttons)
  writer_.write_uint8(self.target)
  if v2 {
    writer_.write_uint16(self.buttons2)
    writer_.write_uint8(self.enabled_extensions)
    writer_.write_int16(self.s)
    writer_.write_int16(self.t)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `ManualControl` from wire-ordered little-endian payload bytes.
pub fn ManualControl::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[ManualControl, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let x = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let y = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let z = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let r = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let buttons = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let buttons2 = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let enabled_extensions = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let s = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let t = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target, x, y, z, r, buttons, buttons2, enabled_extensions, s, t, })
}

///|
/// Message encoding a mission item using integer latitude/longitude in degE7.
/// - MAVLink Message `MISSION_ITEM_INT` (ID: 73, CRC_EXTRA: 38, base_len: 37B, max_len: 38B)
pub(all) struct MissionItemInt {
  target_system : Byte
  target_component : Byte
  seq : UInt32
  frame : Byte
  command : UInt32
  current : Byte
  autocontinue : Byte
  param1 : Float
  param2 : Float
  param3 : Float
  param4 : Float
  x : Int32
  y : Int32
  z : Float
  mission_type : Byte
} derive(Eq, Debug)

///|
pub extend MissionItemInt with Eq::{not_equal, equal}

///|
pub extend MissionItemInt with @debug.Debug::{to_repr}

///|
pub fn MissionItemInt::msg_id() -> UInt32 {
  73U
}

///|
pub fn MissionItemInt::crc_extra() -> Byte {
  b'\x26'
}

///|
pub fn MissionItemInt::base_payload_len() -> Int32 {
  37
}

///|
pub fn MissionItemInt::max_payload_len() -> Int32 {
  38
}

///|
/// Serialize `MissionItemInt` into wire-ordered little-endian payload bytes.
pub fn MissionItemInt::encode_payload(
  self : MissionItemInt,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=38)
  writer_.write_float(self.param1)
  writer_.write_float(self.param2)
  writer_.write_float(self.param3)
  writer_.write_float(self.param4)
  writer_.write_int32(self.x)
  writer_.write_int32(self.y)
  writer_.write_float(self.z)
  writer_.write_uint16(self.seq)
  writer_.write_uint16(self.command)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.write_uint8(self.frame)
  writer_.write_uint8(self.current)
  writer_.write_uint8(self.autocontinue)
  if v2 {
    writer_.write_uint8(self.mission_type)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `MissionItemInt` from wire-ordered little-endian payload bytes.
pub fn MissionItemInt::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[MissionItemInt, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let param1 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param2 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param3 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param4 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let x = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let y = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let z = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let seq = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let command = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let frame = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let current = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let autocontinue = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let mission_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    target_system,
    target_component,
    seq,
    frame,
    command,
    current,
    autocontinue,
    param1,
    param2,
    param3,
    param4,
    x,
    y,
    z,
    mission_type,
  })
}

///|
/// Metrics typically displayed on a HUD for fixed wing aircraft.
/// - MAVLink Message `VFR_HUD` (ID: 74, CRC_EXTRA: 20, base_len: 20B, max_len: 20B)
pub(all) struct VfrHud {
  airspeed : Float
  groundspeed : Float
  heading : Int32
  throttle : UInt32
  alt : Float
  climb : Float
} derive(Eq, Debug)

///|
pub extend VfrHud with Eq::{not_equal, equal}

///|
pub extend VfrHud with @debug.Debug::{to_repr}

///|
pub fn VfrHud::msg_id() -> UInt32 {
  74U
}

///|
pub fn VfrHud::crc_extra() -> Byte {
  b'\x14'
}

///|
pub fn VfrHud::base_payload_len() -> Int32 {
  20
}

///|
pub fn VfrHud::max_payload_len() -> Int32 {
  20
}

///|
/// Serialize `VfrHud` into wire-ordered little-endian payload bytes.
pub fn VfrHud::encode_payload(self : VfrHud, v2~ : Bool = true) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=20)
  writer_.write_float(self.airspeed)
  writer_.write_float(self.groundspeed)
  writer_.write_float(self.alt)
  writer_.write_float(self.climb)
  writer_.write_int16(self.heading)
  writer_.write_uint16(self.throttle)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `VfrHud` from wire-ordered little-endian payload bytes.
pub fn VfrHud::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[VfrHud, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let airspeed = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let groundspeed = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let alt = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let climb = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let heading = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let throttle = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ airspeed, groundspeed, heading, throttle, alt, climb, })
}

///|
/// Message encoding a command with parameters as scaled integers.
/// - MAVLink Message `COMMAND_INT` (ID: 75, CRC_EXTRA: 158, base_len: 35B, max_len: 35B)
pub(all) struct CommandInt {
  target_system : Byte
  target_component : Byte
  frame : Byte
  command : UInt32
  current : Byte
  autocontinue : Byte
  param1 : Float
  param2 : Float
  param3 : Float
  param4 : Float
  x : Int32
  y : Int32
  z : Float
} derive(Eq, Debug)

///|
pub extend CommandInt with Eq::{not_equal, equal}

///|
pub extend CommandInt with @debug.Debug::{to_repr}

///|
pub fn CommandInt::msg_id() -> UInt32 {
  75U
}

///|
pub fn CommandInt::crc_extra() -> Byte {
  b'\x9E'
}

///|
pub fn CommandInt::base_payload_len() -> Int32 {
  35
}

///|
pub fn CommandInt::max_payload_len() -> Int32 {
  35
}

///|
/// Serialize `CommandInt` into wire-ordered little-endian payload bytes.
pub fn CommandInt::encode_payload(
  self : CommandInt,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=35)
  writer_.write_float(self.param1)
  writer_.write_float(self.param2)
  writer_.write_float(self.param3)
  writer_.write_float(self.param4)
  writer_.write_int32(self.x)
  writer_.write_int32(self.y)
  writer_.write_float(self.z)
  writer_.write_uint16(self.command)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.write_uint8(self.frame)
  writer_.write_uint8(self.current)
  writer_.write_uint8(self.autocontinue)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `CommandInt` from wire-ordered little-endian payload bytes.
pub fn CommandInt::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[CommandInt, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let param1 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param2 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param3 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param4 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let x = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let y = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let z = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let command = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let frame = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let current = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let autocontinue = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    target_system,
    target_component,
    frame,
    command,
    current,
    autocontinue,
    param1,
    param2,
    param3,
    param4,
    x,
    y,
    z,
  })
}

///|
/// Send a command with up to seven parameters to the MAV.
/// - MAVLink Message `COMMAND_LONG` (ID: 76, CRC_EXTRA: 152, base_len: 33B, max_len: 33B)
pub(all) struct CommandLong {
  target_system : Byte
  target_component : Byte
  command : UInt32
  confirmation : Byte
  param1 : Float
  param2 : Float
  param3 : Float
  param4 : Float
  param5 : Float
  param6 : Float
  param7 : Float
} derive(Eq, Debug)

///|
pub extend CommandLong with Eq::{not_equal, equal}

///|
pub extend CommandLong with @debug.Debug::{to_repr}

///|
pub fn CommandLong::msg_id() -> UInt32 {
  76U
}

///|
pub fn CommandLong::crc_extra() -> Byte {
  b'\x98'
}

///|
pub fn CommandLong::base_payload_len() -> Int32 {
  33
}

///|
pub fn CommandLong::max_payload_len() -> Int32 {
  33
}

///|
/// Serialize `CommandLong` into wire-ordered little-endian payload bytes.
pub fn CommandLong::encode_payload(
  self : CommandLong,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=33)
  writer_.write_float(self.param1)
  writer_.write_float(self.param2)
  writer_.write_float(self.param3)
  writer_.write_float(self.param4)
  writer_.write_float(self.param5)
  writer_.write_float(self.param6)
  writer_.write_float(self.param7)
  writer_.write_uint16(self.command)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.write_uint8(self.confirmation)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `CommandLong` from wire-ordered little-endian payload bytes.
pub fn CommandLong::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[CommandLong, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let param1 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param2 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param3 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param4 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param5 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param6 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param7 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let command = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let confirmation = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    target_system,
    target_component,
    command,
    confirmation,
    param1,
    param2,
    param3,
    param4,
    param5,
    param6,
    param7,
  })
}

///|
/// Report status of a command. Includes feedback whether the command was executed.
/// - MAVLink Message `COMMAND_ACK` (ID: 77, CRC_EXTRA: 143, base_len: 3B, max_len: 10B)
pub(all) struct CommandAck {
  command : UInt32
  result : Byte
  progress : Byte
  result_param2 : Int32
  target_system : Byte
  target_component : Byte
} derive(Eq, Debug)

///|
pub extend CommandAck with Eq::{not_equal, equal}

///|
pub extend CommandAck with @debug.Debug::{to_repr}

///|
pub fn CommandAck::msg_id() -> UInt32 {
  77U
}

///|
pub fn CommandAck::crc_extra() -> Byte {
  b'\x8F'
}

///|
pub fn CommandAck::base_payload_len() -> Int32 {
  3
}

///|
pub fn CommandAck::max_payload_len() -> Int32 {
  10
}

///|
/// Serialize `CommandAck` into wire-ordered little-endian payload bytes.
pub fn CommandAck::encode_payload(
  self : CommandAck,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=10)
  writer_.write_uint16(self.command)
  writer_.write_uint8(self.result)
  if v2 {
    writer_.write_uint8(self.progress)
    writer_.write_int32(self.result_param2)
    writer_.write_uint8(self.target_system)
    writer_.write_uint8(self.target_component)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `CommandAck` from wire-ordered little-endian payload bytes.
pub fn CommandAck::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[CommandAck, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let command = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let result = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let progress = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let result_param2 = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    command,
    result,
    progress,
    result_param2,
    target_system,
    target_component,
  })
}

///|
/// Cancel a long running command.
/// - MAVLink Message `COMMAND_CANCEL` (ID: 80, CRC_EXTRA: 14, base_len: 4B, max_len: 4B)
pub(all) struct CommandCancel {
  target_system : Byte
  target_component : Byte
  command : UInt32
} derive(Eq, Debug)

///|
pub extend CommandCancel with Eq::{not_equal, equal}

///|
pub extend CommandCancel with @debug.Debug::{to_repr}

///|
pub fn CommandCancel::msg_id() -> UInt32 {
  80U
}

///|
pub fn CommandCancel::crc_extra() -> Byte {
  b'\x0E'
}

///|
pub fn CommandCancel::base_payload_len() -> Int32 {
  4
}

///|
pub fn CommandCancel::max_payload_len() -> Int32 {
  4
}

///|
/// Serialize `CommandCancel` into wire-ordered little-endian payload bytes.
pub fn CommandCancel::encode_payload(
  self : CommandCancel,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=4)
  writer_.write_uint16(self.command)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `CommandCancel` from wire-ordered little-endian payload bytes.
pub fn CommandCancel::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[CommandCancel, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let command = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, command, })
}

///|
/// Sets a desired vehicle attitude. Used by an external controller to command the vehicle.
/// - MAVLink Message `SET_ATTITUDE_TARGET` (ID: 82, CRC_EXTRA: 49, base_len: 39B, max_len: 39B)
pub(all) struct SetAttitudeTarget {
  time_boot_ms : UInt32
  target_system : Byte
  target_component : Byte
  type_mask : Byte
  q : FixedArray[Float]
  body_roll_rate : Float
  body_pitch_rate : Float
  body_yaw_rate : Float
  thrust : Float
} derive(Eq, Debug)

///|
pub extend SetAttitudeTarget with Eq::{not_equal, equal}

///|
pub extend SetAttitudeTarget with @debug.Debug::{to_repr}

///|
pub fn SetAttitudeTarget::msg_id() -> UInt32 {
  82U
}

///|
pub fn SetAttitudeTarget::crc_extra() -> Byte {
  b'\x31'
}

///|
pub fn SetAttitudeTarget::base_payload_len() -> Int32 {
  39
}

///|
pub fn SetAttitudeTarget::max_payload_len() -> Int32 {
  39
}

///|
/// Serialize `SetAttitudeTarget` into wire-ordered little-endian payload bytes.
pub fn SetAttitudeTarget::encode_payload(
  self : SetAttitudeTarget,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=39)
  writer_.write_uint32(self.time_boot_ms)
  for idx_ = 0; idx_ < 4; idx_ = idx_ + 1 {
    let elem_ = if idx_ < self.q.length() {
      self.q[idx_]
    } else {
      (0.0 : Float)
    }
    writer_.write_float(elem_)
  }
  writer_.write_float(self.body_roll_rate)
  writer_.write_float(self.body_pitch_rate)
  writer_.write_float(self.body_yaw_rate)
  writer_.write_float(self.thrust)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.write_uint8(self.type_mask)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `SetAttitudeTarget` from wire-ordered little-endian payload bytes.
pub fn SetAttitudeTarget::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[SetAttitudeTarget, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_boot_ms = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let q = FixedArray::make(4, (0.0 : Float))
  for idx_ = 0; idx_ < 4; idx_ = idx_ + 1 {
    match reader_.read_float() {
      Ok(v) => q[idx_] = v
      Err(e) => return Err(e)
    }
  }
  let body_roll_rate = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let body_pitch_rate = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let body_yaw_rate = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let thrust = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let type_mask = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    time_boot_ms,
    target_system,
    target_component,
    type_mask,
    q,
    body_roll_rate,
    body_pitch_rate,
    body_yaw_rate,
    thrust,
  })
}

///|
/// Time synchronization message.
/// - MAVLink Message `TIMESYNC` (ID: 111, CRC_EXTRA: 34, base_len: 16B, max_len: 18B)
pub(all) struct Timesync {
  tc1 : Int64
  ts1 : Int64
  target_system : Byte
  target_component : Byte
} derive(Eq, Debug)

///|
pub extend Timesync with Eq::{not_equal, equal}

///|
pub extend Timesync with @debug.Debug::{to_repr}

///|
pub fn Timesync::msg_id() -> UInt32 {
  111U
}

///|
pub fn Timesync::crc_extra() -> Byte {
  b'\x22'
}

///|
pub fn Timesync::base_payload_len() -> Int32 {
  16
}

///|
pub fn Timesync::max_payload_len() -> Int32 {
  18
}

///|
/// Serialize `Timesync` into wire-ordered little-endian payload bytes.
pub fn Timesync::encode_payload(self : Timesync, v2~ : Bool = true) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=18)
  writer_.write_int64(self.tc1)
  writer_.write_int64(self.ts1)
  if v2 {
    writer_.write_uint8(self.target_system)
    writer_.write_uint8(self.target_component)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `Timesync` from wire-ordered little-endian payload bytes.
pub fn Timesync::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[Timesync, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let tc1 = match reader_.read_int64() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let ts1 = match reader_.read_int64() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ tc1, ts1, target_system, target_component, })
}

///|
/// Distance sensor information for an onboard rangefinder.
/// - MAVLink Message `DISTANCE_SENSOR` (ID: 132, CRC_EXTRA: 85, base_len: 14B, max_len: 39B)
pub(all) struct DistanceSensor {
  time_boot_ms : UInt32
  min_distance : UInt32
  max_distance : UInt32
  current_distance : UInt32
  mav_type : Byte
  id : Byte
  orientation : Byte
  covariance : Byte
  horizontal_fov : Float
  vertical_fov : Float
  quaternion : FixedArray[Float]
  signal_quality : Byte
} derive(Eq, Debug)

///|
pub extend DistanceSensor with Eq::{not_equal, equal}

///|
pub extend DistanceSensor with @debug.Debug::{to_repr}

///|
pub fn DistanceSensor::msg_id() -> UInt32 {
  132U
}

///|
pub fn DistanceSensor::crc_extra() -> Byte {
  b'\x55'
}

///|
pub fn DistanceSensor::base_payload_len() -> Int32 {
  14
}

///|
pub fn DistanceSensor::max_payload_len() -> Int32 {
  39
}

///|
/// Serialize `DistanceSensor` into wire-ordered little-endian payload bytes.
pub fn DistanceSensor::encode_payload(
  self : DistanceSensor,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=39)
  writer_.write_uint32(self.time_boot_ms)
  writer_.write_uint16(self.min_distance)
  writer_.write_uint16(self.max_distance)
  writer_.write_uint16(self.current_distance)
  writer_.write_uint8(self.mav_type)
  writer_.write_uint8(self.id)
  writer_.write_uint8(self.orientation)
  writer_.write_uint8(self.covariance)
  if v2 {
    writer_.write_float(self.horizontal_fov)
    writer_.write_float(self.vertical_fov)
    for idx_ = 0; idx_ < 4; idx_ = idx_ + 1 {
      let elem_ = if idx_ < self.quaternion.length() {
        self.quaternion[idx_]
      } else {
        (0.0 : Float)
      }
      writer_.write_float(elem_)
    }
    writer_.write_uint8(self.signal_quality)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `DistanceSensor` from wire-ordered little-endian payload bytes.
pub fn DistanceSensor::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[DistanceSensor, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_boot_ms = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let min_distance = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let max_distance = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let current_distance = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let mav_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let id = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let orientation = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let covariance = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let horizontal_fov = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vertical_fov = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let quaternion = FixedArray::make(4, (0.0 : Float))
  for idx_ = 0; idx_ < 4; idx_ = idx_ + 1 {
    match reader_.read_float() {
      Ok(v) => quaternion[idx_] = v
      Err(e) => return Err(e)
    }
  }
  let signal_quality = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    time_boot_ms,
    min_distance,
    max_distance,
    current_distance,
    mav_type,
    id,
    orientation,
    covariance,
    horizontal_fov,
    vertical_fov,
    quaternion,
    signal_quality,
  })
}

///|
/// Battery information.
/// - MAVLink Message `BATTERY_STATUS` (ID: 147, CRC_EXTRA: 154, base_len: 36B, max_len: 54B)
pub(all) struct BatteryStatus {
  id : Byte
  battery_function : Byte
  mav_type : Byte
  temperature : Int32
  voltages : FixedArray[UInt32]
  current_battery : Int32
  current_consumed : Int32
  energy_consumed : Int32
  battery_remaining : Int32
  time_remaining : Int32
  charge_state : Byte
  voltages_ext : FixedArray[UInt32]
  mode : Byte
  fault_bitmask : UInt32
} derive(Eq, Debug)

///|
pub extend BatteryStatus with Eq::{not_equal, equal}

///|
pub extend BatteryStatus with @debug.Debug::{to_repr}

///|
pub fn BatteryStatus::msg_id() -> UInt32 {
  147U
}

///|
pub fn BatteryStatus::crc_extra() -> Byte {
  b'\x9A'
}

///|
pub fn BatteryStatus::base_payload_len() -> Int32 {
  36
}

///|
pub fn BatteryStatus::max_payload_len() -> Int32 {
  54
}

///|
/// Serialize `BatteryStatus` into wire-ordered little-endian payload bytes.
pub fn BatteryStatus::encode_payload(
  self : BatteryStatus,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=54)
  writer_.write_int32(self.current_consumed)
  writer_.write_int32(self.energy_consumed)
  writer_.write_int16(self.temperature)
  for idx_ = 0; idx_ < 10; idx_ = idx_ + 1 {
    let elem_ = if idx_ < self.voltages.length() {
      self.voltages[idx_]
    } else {
      0U
    }
    writer_.write_uint16(elem_)
  }
  writer_.write_int16(self.current_battery)
  writer_.write_uint8(self.id)
  writer_.write_uint8(self.battery_function)
  writer_.write_uint8(self.mav_type)
  writer_.write_int8(self.battery_remaining)
  if v2 {
    writer_.write_int32(self.time_remaining)
    writer_.write_uint8(self.charge_state)
    for idx_ = 0; idx_ < 4; idx_ = idx_ + 1 {
      let elem_ = if idx_ < self.voltages_ext.length() {
        self.voltages_ext[idx_]
      } else {
        0U
      }
      writer_.write_uint16(elem_)
    }
    writer_.write_uint8(self.mode)
    writer_.write_uint32(self.fault_bitmask)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `BatteryStatus` from wire-ordered little-endian payload bytes.
pub fn BatteryStatus::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[BatteryStatus, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let current_consumed = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let energy_consumed = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let temperature = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let voltages = FixedArray::make(10, 0U)
  for idx_ = 0; idx_ < 10; idx_ = idx_ + 1 {
    match reader_.read_uint16() {
      Ok(v) => voltages[idx_] = v
      Err(e) => return Err(e)
    }
  }
  let current_battery = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let id = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let battery_function = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let mav_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let battery_remaining = match reader_.read_int8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let time_remaining = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let charge_state = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let voltages_ext = FixedArray::make(4, 0U)
  for idx_ = 0; idx_ < 4; idx_ = idx_ + 1 {
    match reader_.read_uint16() {
      Ok(v) => voltages_ext[idx_] = v
      Err(e) => return Err(e)
    }
  }
  let mode = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let fault_bitmask = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    id,
    battery_function,
    mav_type,
    temperature,
    voltages,
    current_battery,
    current_consumed,
    energy_consumed,
    battery_remaining,
    time_remaining,
    charge_state,
    voltages_ext,
    mode,
    fault_bitmask,
  })
}

///|
/// Version and capability of autopilot software.
/// - MAVLink Message `AUTOPILOT_VERSION` (ID: 148, CRC_EXTRA: 178, base_len: 60B, max_len: 78B)
pub(all) struct AutopilotVersion {
  capabilities : UInt64
  flight_sw_version : UInt32
  middleware_sw_version : UInt32
  os_sw_version : UInt32
  board_version : UInt32
  flight_custom_version : FixedArray[Byte]
  middleware_custom_version : FixedArray[Byte]
  os_custom_version : FixedArray[Byte]
  vendor_id : UInt32
  product_id : UInt32
  uid : UInt64
  uid2 : FixedArray[Byte]
} derive(Eq, Debug)

///|
pub extend AutopilotVersion with Eq::{not_equal, equal}

///|
pub extend AutopilotVersion with @debug.Debug::{to_repr}

///|
pub fn AutopilotVersion::msg_id() -> UInt32 {
  148U
}

///|
pub fn AutopilotVersion::crc_extra() -> Byte {
  b'\xB2'
}

///|
pub fn AutopilotVersion::base_payload_len() -> Int32 {
  60
}

///|
pub fn AutopilotVersion::max_payload_len() -> Int32 {
  78
}

///|
/// Serialize `AutopilotVersion` into wire-ordered little-endian payload bytes.
pub fn AutopilotVersion::encode_payload(
  self : AutopilotVersion,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=78)
  writer_.write_uint64(self.capabilities)
  writer_.write_uint64(self.uid)
  writer_.write_uint32(self.flight_sw_version)
  writer_.write_uint32(self.middleware_sw_version)
  writer_.write_uint32(self.os_sw_version)
  writer_.write_uint32(self.board_version)
  writer_.write_uint16(self.vendor_id)
  writer_.write_uint16(self.product_id)
  for idx_ = 0; idx_ < 8; idx_ = idx_ + 1 {
    let elem_ = if idx_ < self.flight_custom_version.length() {
      self.flight_custom_version[idx_]
    } else {
      b'\x00'
    }
    writer_.write_uint8(elem_)
  }
  for idx_ = 0; idx_ < 8; idx_ = idx_ + 1 {
    let elem_ = if idx_ < self.middleware_custom_version.length() {
      self.middleware_custom_version[idx_]
    } else {
      b'\x00'
    }
    writer_.write_uint8(elem_)
  }
  for idx_ = 0; idx_ < 8; idx_ = idx_ + 1 {
    let elem_ = if idx_ < self.os_custom_version.length() {
      self.os_custom_version[idx_]
    } else {
      b'\x00'
    }
    writer_.write_uint8(elem_)
  }
  if v2 {
    for idx_ = 0; idx_ < 18; idx_ = idx_ + 1 {
      let elem_ = if idx_ < self.uid2.length() {
        self.uid2[idx_]
      } else {
        b'\x00'
      }
      writer_.write_uint8(elem_)
    }
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `AutopilotVersion` from wire-ordered little-endian payload bytes.
pub fn AutopilotVersion::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[AutopilotVersion, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let capabilities = match reader_.read_uint64() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let uid = match reader_.read_uint64() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let flight_sw_version = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let middleware_sw_version = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let os_sw_version = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let board_version = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vendor_id = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let product_id = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let flight_custom_version = FixedArray::make(8, b'\x00')
  for idx_ = 0; idx_ < 8; idx_ = idx_ + 1 {
    match reader_.read_uint8() {
      Ok(v) => flight_custom_version[idx_] = v
      Err(e) => return Err(e)
    }
  }
  let middleware_custom_version = FixedArray::make(8, b'\x00')
  for idx_ = 0; idx_ < 8; idx_ = idx_ + 1 {
    match reader_.read_uint8() {
      Ok(v) => middleware_custom_version[idx_] = v
      Err(e) => return Err(e)
    }
  }
  let os_custom_version = FixedArray::make(8, b'\x00')
  for idx_ = 0; idx_ < 8; idx_ = idx_ + 1 {
    match reader_.read_uint8() {
      Ok(v) => os_custom_version[idx_] = v
      Err(e) => return Err(e)
    }
  }
  reader_.zero_extend = true
  let uid2 = FixedArray::make(18, b'\x00')
  for idx_ = 0; idx_ < 18; idx_ = idx_ + 1 {
    match reader_.read_uint8() {
      Ok(v) => uid2[idx_] = v
      Err(e) => return Err(e)
    }
  }
  Ok({
    capabilities,
    flight_sw_version,
    middleware_sw_version,
    os_sw_version,
    board_version,
    flight_custom_version,
    middleware_custom_version,
    os_custom_version,
    vendor_id,
    product_id,
    uid,
    uid2,
  })
}

///|
/// Provides state for additional features.
/// - MAVLink Message `EXTENDED_SYS_STATE` (ID: 245, CRC_EXTRA: 130, base_len: 2B, max_len: 2B)
pub(all) struct ExtendedSysState {
  vtol_state : Byte
  landed_state : Byte
} derive(Eq, Debug)

///|
pub extend ExtendedSysState with Eq::{not_equal, equal}

///|
pub extend ExtendedSysState with @debug.Debug::{to_repr}

///|
pub fn ExtendedSysState::msg_id() -> UInt32 {
  245U
}

///|
pub fn ExtendedSysState::crc_extra() -> Byte {
  b'\x82'
}

///|
pub fn ExtendedSysState::base_payload_len() -> Int32 {
  2
}

///|
pub fn ExtendedSysState::max_payload_len() -> Int32 {
  2
}

///|
/// Serialize `ExtendedSysState` into wire-ordered little-endian payload bytes.
pub fn ExtendedSysState::encode_payload(
  self : ExtendedSysState,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=2)
  writer_.write_uint8(self.vtol_state)
  writer_.write_uint8(self.landed_state)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `ExtendedSysState` from wire-ordered little-endian payload bytes.
pub fn ExtendedSysState::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[ExtendedSysState, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let vtol_state = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let landed_state = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ vtol_state, landed_state, })
}

///|
/// Status text message.
/// - MAVLink Message `STATUSTEXT` (ID: 253, CRC_EXTRA: 83, base_len: 51B, max_len: 54B)
pub(all) struct Statustext {
  severity : Byte
  text : String
  id : UInt32
  chunk_seq : Byte
} derive(Eq, Debug)

///|
pub extend Statustext with Eq::{not_equal, equal}

///|
pub extend Statustext with @debug.Debug::{to_repr}

///|
pub fn Statustext::msg_id() -> UInt32 {
  253U
}

///|
pub fn Statustext::crc_extra() -> Byte {
  b'\x53'
}

///|
pub fn Statustext::base_payload_len() -> Int32 {
  51
}

///|
pub fn Statustext::max_payload_len() -> Int32 {
  54
}

///|
/// Serialize `Statustext` into wire-ordered little-endian payload bytes.
pub fn Statustext::encode_payload(
  self : Statustext,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=54)
  writer_.write_uint8(self.severity)
  writer_.write_char_array(self.text, 50)
  if v2 {
    writer_.write_uint16(self.id)
    writer_.write_uint8(self.chunk_seq)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `Statustext` from wire-ordered little-endian payload bytes.
pub fn Statustext::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[Statustext, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let severity = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let text = match reader_.read_char_array(50) {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let id = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let chunk_seq = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ severity, text, id, chunk_seq, })
}

///|
/// Send a debug value. The index is used to discriminate between values.
/// - MAVLink Message `DEBUG` (ID: 254, CRC_EXTRA: 46, base_len: 9B, max_len: 9B)
pub(all) struct MavDebug {
  time_boot_ms : UInt32
  ind : Byte
  value : Float
} derive(Eq, Debug)

///|
pub extend MavDebug with Eq::{not_equal, equal}

///|
pub extend MavDebug with @debug.Debug::{to_repr}

///|
pub fn MavDebug::msg_id() -> UInt32 {
  254U
}

///|
pub fn MavDebug::crc_extra() -> Byte {
  b'\x2E'
}

///|
pub fn MavDebug::base_payload_len() -> Int32 {
  9
}

///|
pub fn MavDebug::max_payload_len() -> Int32 {
  9
}

///|
/// Serialize `MavDebug` into wire-ordered little-endian payload bytes.
pub fn MavDebug::encode_payload(self : MavDebug, v2~ : Bool = true) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=9)
  writer_.write_uint32(self.time_boot_ms)
  writer_.write_float(self.value)
  writer_.write_uint8(self.ind)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `MavDebug` from wire-ordered little-endian payload bytes.
pub fn MavDebug::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[MavDebug, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_boot_ms = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let value = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let ind = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ time_boot_ms, ind, value, })
}

///|
/// An ack for a LOGGING_DATA_ACKED message (requires 24-bit MAVLink v2 message ID).
/// - MAVLink Message `LOGGING_ACK` (ID: 268, CRC_EXTRA: 14, base_len: 4B, max_len: 4B)
pub(all) struct LoggingAck {
  target_system : Byte
  target_component : Byte
  sequence : UInt32
} derive(Eq, Debug)

///|
pub extend LoggingAck with Eq::{not_equal, equal}

///|
pub extend LoggingAck with @debug.Debug::{to_repr}

///|
pub fn LoggingAck::msg_id() -> UInt32 {
  268U
}

///|
pub fn LoggingAck::crc_extra() -> Byte {
  b'\x0E'
}

///|
pub fn LoggingAck::base_payload_len() -> Int32 {
  4
}

///|
pub fn LoggingAck::max_payload_len() -> Int32 {
  4
}

///|
/// Serialize `LoggingAck` into wire-ordered little-endian payload bytes.
pub fn LoggingAck::encode_payload(
  self : LoggingAck,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=4)
  writer_.write_uint16(self.sequence)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `LoggingAck` from wire-ordered little-endian payload bytes.
pub fn LoggingAck::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[LoggingAck, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let sequence = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, sequence, })
}

///|
/// This message is sent to the MAV to write a partial list. If start index == end index, only one item will be transmitted / updated.
/// - MAVLink Message `MISSION_WRITE_PARTIAL_LIST` (ID: 38, CRC_EXTRA: 9, base_len: 6B, max_len: 7B)
pub(all) struct MissionWritePartialList {
  target_system : Byte
  target_component : Byte
  start_index : Int32
  end_index : Int32
  mission_type : Byte
} derive(Eq, Debug)

///|
pub extend MissionWritePartialList with Eq::{not_equal, equal}

///|
pub extend MissionWritePartialList with @debug.Debug::{to_repr}

///|
pub fn MissionWritePartialList::msg_id() -> UInt32 {
  38U
}

///|
pub fn MissionWritePartialList::crc_extra() -> Byte {
  b'\x09'
}

///|
pub fn MissionWritePartialList::base_payload_len() -> Int32 {
  6
}

///|
pub fn MissionWritePartialList::max_payload_len() -> Int32 {
  7
}

///|
/// Serialize `MissionWritePartialList` into wire-ordered little-endian payload bytes.
pub fn MissionWritePartialList::encode_payload(
  self : MissionWritePartialList,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=7)
  writer_.write_int16(self.start_index)
  writer_.write_int16(self.end_index)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  if v2 {
    writer_.write_uint8(self.mission_type)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `MissionWritePartialList` from wire-ordered little-endian payload bytes.
pub fn MissionWritePartialList::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[MissionWritePartialList, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let start_index = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let end_index = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let mission_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, start_index, end_index, mission_type, })
}

///|
/// Message encoding a mission item (legacy floating-point coordinates).
/// - MAVLink Message `MISSION_ITEM` (ID: 39, CRC_EXTRA: 254, base_len: 37B, max_len: 38B)
pub(all) struct MissionItem {
  target_system : Byte
  target_component : Byte
  seq : UInt32
  frame : Byte
  command : UInt32
  current : Byte
  autocontinue : Byte
  param1 : Float
  param2 : Float
  param3 : Float
  param4 : Float
  x : Float
  y : Float
  z : Float
  mission_type : Byte
} derive(Eq, Debug)

///|
pub extend MissionItem with Eq::{not_equal, equal}

///|
pub extend MissionItem with @debug.Debug::{to_repr}

///|
pub fn MissionItem::msg_id() -> UInt32 {
  39U
}

///|
pub fn MissionItem::crc_extra() -> Byte {
  b'\xFE'
}

///|
pub fn MissionItem::base_payload_len() -> Int32 {
  37
}

///|
pub fn MissionItem::max_payload_len() -> Int32 {
  38
}

///|
/// Serialize `MissionItem` into wire-ordered little-endian payload bytes.
pub fn MissionItem::encode_payload(
  self : MissionItem,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=38)
  writer_.write_float(self.param1)
  writer_.write_float(self.param2)
  writer_.write_float(self.param3)
  writer_.write_float(self.param4)
  writer_.write_float(self.x)
  writer_.write_float(self.y)
  writer_.write_float(self.z)
  writer_.write_uint16(self.seq)
  writer_.write_uint16(self.command)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.write_uint8(self.frame)
  writer_.write_uint8(self.current)
  writer_.write_uint8(self.autocontinue)
  if v2 {
    writer_.write_uint8(self.mission_type)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `MissionItem` from wire-ordered little-endian payload bytes.
pub fn MissionItem::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[MissionItem, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let param1 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param2 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param3 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param4 = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let x = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let y = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let z = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let seq = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let command = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let frame = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let current = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let autocontinue = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let mission_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    target_system,
    target_component,
    seq,
    frame,
    command,
    current,
    autocontinue,
    param1,
    param2,
    param3,
    param4,
    x,
    y,
    z,
    mission_type,
  })
}

///|
/// Reports the current commanded vehicle attitude as specified by the autopilot.
/// - MAVLink Message `ATTITUDE_TARGET` (ID: 83, CRC_EXTRA: 22, base_len: 37B, max_len: 37B)
pub(all) struct AttitudeTarget {
  time_boot_ms : UInt32
  type_mask : Byte
  q : FixedArray[Float]
  body_roll_rate : Float
  body_pitch_rate : Float
  body_yaw_rate : Float
  thrust : Float
} derive(Eq, Debug)

///|
pub extend AttitudeTarget with Eq::{not_equal, equal}

///|
pub extend AttitudeTarget with @debug.Debug::{to_repr}

///|
pub fn AttitudeTarget::msg_id() -> UInt32 {
  83U
}

///|
pub fn AttitudeTarget::crc_extra() -> Byte {
  b'\x16'
}

///|
pub fn AttitudeTarget::base_payload_len() -> Int32 {
  37
}

///|
pub fn AttitudeTarget::max_payload_len() -> Int32 {
  37
}

///|
/// Serialize `AttitudeTarget` into wire-ordered little-endian payload bytes.
pub fn AttitudeTarget::encode_payload(
  self : AttitudeTarget,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=37)
  writer_.write_uint32(self.time_boot_ms)
  for idx_ = 0; idx_ < 4; idx_ = idx_ + 1 {
    let elem_ = if idx_ < self.q.length() {
      self.q[idx_]
    } else {
      (0.0 : Float)
    }
    writer_.write_float(elem_)
  }
  writer_.write_float(self.body_roll_rate)
  writer_.write_float(self.body_pitch_rate)
  writer_.write_float(self.body_yaw_rate)
  writer_.write_float(self.thrust)
  writer_.write_uint8(self.type_mask)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `AttitudeTarget` from wire-ordered little-endian payload bytes.
pub fn AttitudeTarget::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[AttitudeTarget, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_boot_ms = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let q = FixedArray::make(4, (0.0 : Float))
  for idx_ = 0; idx_ < 4; idx_ = idx_ + 1 {
    match reader_.read_float() {
      Ok(v) => q[idx_] = v
      Err(e) => return Err(e)
    }
  }
  let body_roll_rate = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let body_pitch_rate = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let body_yaw_rate = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let thrust = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let type_mask = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    time_boot_ms,
    type_mask,
    q,
    body_roll_rate,
    body_pitch_rate,
    body_yaw_rate,
    thrust,
  })
}

///|
/// Sets a desired vehicle position in a local north-east-down coordinate frame.
/// - MAVLink Message `SET_POSITION_TARGET_LOCAL_NED` (ID: 84, CRC_EXTRA: 143, base_len: 53B, max_len: 53B)
pub(all) struct SetPositionTargetLocalNed {
  time_boot_ms : UInt32
  target_system : Byte
  target_component : Byte
  coordinate_frame : Byte
  type_mask : UInt32
  x : Float
  y : Float
  z : Float
  vx : Float
  vy : Float
  vz : Float
  afx : Float
  afy : Float
  afz : Float
  yaw : Float
  yaw_rate : Float
} derive(Eq, Debug)

///|
pub extend SetPositionTargetLocalNed with Eq::{not_equal, equal}

///|
pub extend SetPositionTargetLocalNed with @debug.Debug::{to_repr}

///|
pub fn SetPositionTargetLocalNed::msg_id() -> UInt32 {
  84U
}

///|
pub fn SetPositionTargetLocalNed::crc_extra() -> Byte {
  b'\x8F'
}

///|
pub fn SetPositionTargetLocalNed::base_payload_len() -> Int32 {
  53
}

///|
pub fn SetPositionTargetLocalNed::max_payload_len() -> Int32 {
  53
}

///|
/// Serialize `SetPositionTargetLocalNed` into wire-ordered little-endian payload bytes.
pub fn SetPositionTargetLocalNed::encode_payload(
  self : SetPositionTargetLocalNed,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=53)
  writer_.write_uint32(self.time_boot_ms)
  writer_.write_float(self.x)
  writer_.write_float(self.y)
  writer_.write_float(self.z)
  writer_.write_float(self.vx)
  writer_.write_float(self.vy)
  writer_.write_float(self.vz)
  writer_.write_float(self.afx)
  writer_.write_float(self.afy)
  writer_.write_float(self.afz)
  writer_.write_float(self.yaw)
  writer_.write_float(self.yaw_rate)
  writer_.write_uint16(self.type_mask)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.write_uint8(self.coordinate_frame)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `SetPositionTargetLocalNed` from wire-ordered little-endian payload bytes.
pub fn SetPositionTargetLocalNed::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[SetPositionTargetLocalNed, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_boot_ms = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let x = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let y = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let z = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vx = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vy = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vz = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let afx = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let afy = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let afz = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let yaw = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let yaw_rate = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let type_mask = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let coordinate_frame = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    time_boot_ms,
    target_system,
    target_component,
    coordinate_frame,
    type_mask,
    x,
    y,
    z,
    vx,
    vy,
    vz,
    afx,
    afy,
    afz,
    yaw,
    yaw_rate,
  })
}

///|
/// Reports the current commanded vehicle position, velocity, and acceleration as specified by the autopilot.
/// - MAVLink Message `POSITION_TARGET_LOCAL_NED` (ID: 85, CRC_EXTRA: 140, base_len: 51B, max_len: 51B)
pub(all) struct PositionTargetLocalNed {
  time_boot_ms : UInt32
  coordinate_frame : Byte
  type_mask : UInt32
  x : Float
  y : Float
  z : Float
  vx : Float
  vy : Float
  vz : Float
  afx : Float
  afy : Float
  afz : Float
  yaw : Float
  yaw_rate : Float
} derive(Eq, Debug)

///|
pub extend PositionTargetLocalNed with Eq::{not_equal, equal}

///|
pub extend PositionTargetLocalNed with @debug.Debug::{to_repr}

///|
pub fn PositionTargetLocalNed::msg_id() -> UInt32 {
  85U
}

///|
pub fn PositionTargetLocalNed::crc_extra() -> Byte {
  b'\x8C'
}

///|
pub fn PositionTargetLocalNed::base_payload_len() -> Int32 {
  51
}

///|
pub fn PositionTargetLocalNed::max_payload_len() -> Int32 {
  51
}

///|
/// Serialize `PositionTargetLocalNed` into wire-ordered little-endian payload bytes.
pub fn PositionTargetLocalNed::encode_payload(
  self : PositionTargetLocalNed,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=51)
  writer_.write_uint32(self.time_boot_ms)
  writer_.write_float(self.x)
  writer_.write_float(self.y)
  writer_.write_float(self.z)
  writer_.write_float(self.vx)
  writer_.write_float(self.vy)
  writer_.write_float(self.vz)
  writer_.write_float(self.afx)
  writer_.write_float(self.afy)
  writer_.write_float(self.afz)
  writer_.write_float(self.yaw)
  writer_.write_float(self.yaw_rate)
  writer_.write_uint16(self.type_mask)
  writer_.write_uint8(self.coordinate_frame)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `PositionTargetLocalNed` from wire-ordered little-endian payload bytes.
pub fn PositionTargetLocalNed::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[PositionTargetLocalNed, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_boot_ms = match reader_.read_uint32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let x = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let y = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let z = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vx = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vy = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let vz = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let afx = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let afy = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let afz = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let yaw = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let yaw_rate = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let type_mask = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let coordinate_frame = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    time_boot_ms,
    coordinate_frame,
    type_mask,
    x,
    y,
    z,
    vx,
    vy,
    vz,
    afx,
    afy,
    afz,
    yaw,
    yaw_rate,
  })
}

///|
/// Optical flow from a flow sensor (e.g. optical mouse sensor).
/// - MAVLink Message `OPTICAL_FLOW` (ID: 100, CRC_EXTRA: 175, base_len: 26B, max_len: 34B)
pub(all) struct OpticalFlow {
  time_usec : UInt64
  sensor_id : Byte
  flow_x : Int32
  flow_y : Int32
  flow_comp_m_x : Float
  flow_comp_m_y : Float
  quality : Byte
  ground_distance : Float
  flow_rate_x : Float
  flow_rate_y : Float
} derive(Eq, Debug)

///|
pub extend OpticalFlow with Eq::{not_equal, equal}

///|
pub extend OpticalFlow with @debug.Debug::{to_repr}

///|
pub fn OpticalFlow::msg_id() -> UInt32 {
  100U
}

///|
pub fn OpticalFlow::crc_extra() -> Byte {
  b'\xAF'
}

///|
pub fn OpticalFlow::base_payload_len() -> Int32 {
  26
}

///|
pub fn OpticalFlow::max_payload_len() -> Int32 {
  34
}

///|
/// Serialize `OpticalFlow` into wire-ordered little-endian payload bytes.
pub fn OpticalFlow::encode_payload(
  self : OpticalFlow,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=34)
  writer_.write_uint64(self.time_usec)
  writer_.write_float(self.flow_comp_m_x)
  writer_.write_float(self.flow_comp_m_y)
  writer_.write_float(self.ground_distance)
  writer_.write_int16(self.flow_x)
  writer_.write_int16(self.flow_y)
  writer_.write_uint8(self.sensor_id)
  writer_.write_uint8(self.quality)
  if v2 {
    writer_.write_float(self.flow_rate_x)
    writer_.write_float(self.flow_rate_y)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `OpticalFlow` from wire-ordered little-endian payload bytes.
pub fn OpticalFlow::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[OpticalFlow, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_usec = match reader_.read_uint64() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let flow_comp_m_x = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let flow_comp_m_y = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let ground_distance = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let flow_x = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let flow_y = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let sensor_id = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let quality = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let flow_rate_x = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let flow_rate_y = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    time_usec,
    sensor_id,
    flow_x,
    flow_y,
    flow_comp_m_x,
    flow_comp_m_y,
    quality,
    ground_distance,
    flow_rate_x,
    flow_rate_y,
  })
}

///|
/// The IMU readings in SI units in NED body frame.
/// - MAVLink Message `HIGHRES_IMU` (ID: 105, CRC_EXTRA: 93, base_len: 62B, max_len: 63B)
pub(all) struct HighresImu {
  time_usec : UInt64
  xacc : Float
  yacc : Float
  zacc : Float
  xgyro : Float
  ygyro : Float
  zgyro : Float
  xmag : Float
  ymag : Float
  zmag : Float
  abs_pressure : Float
  diff_pressure : Float
  pressure_alt : Float
  temperature : Float
  fields_updated : UInt32
  id : Byte
} derive(Eq, Debug)

///|
pub extend HighresImu with Eq::{not_equal, equal}

///|
pub extend HighresImu with @debug.Debug::{to_repr}

///|
pub fn HighresImu::msg_id() -> UInt32 {
  105U
}

///|
pub fn HighresImu::crc_extra() -> Byte {
  b'\x5D'
}

///|
pub fn HighresImu::base_payload_len() -> Int32 {
  62
}

///|
pub fn HighresImu::max_payload_len() -> Int32 {
  63
}

///|
/// Serialize `HighresImu` into wire-ordered little-endian payload bytes.
pub fn HighresImu::encode_payload(
  self : HighresImu,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=63)
  writer_.write_uint64(self.time_usec)
  writer_.write_float(self.xacc)
  writer_.write_float(self.yacc)
  writer_.write_float(self.zacc)
  writer_.write_float(self.xgyro)
  writer_.write_float(self.ygyro)
  writer_.write_float(self.zgyro)
  writer_.write_float(self.xmag)
  writer_.write_float(self.ymag)
  writer_.write_float(self.zmag)
  writer_.write_float(self.abs_pressure)
  writer_.write_float(self.diff_pressure)
  writer_.write_float(self.pressure_alt)
  writer_.write_float(self.temperature)
  writer_.write_uint16(self.fields_updated)
  if v2 {
    writer_.write_uint8(self.id)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `HighresImu` from wire-ordered little-endian payload bytes.
pub fn HighresImu::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[HighresImu, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let time_usec = match reader_.read_uint64() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let xacc = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let yacc = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let zacc = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let xgyro = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let ygyro = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let zgyro = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let xmag = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let ymag = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let zmag = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let abs_pressure = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let diff_pressure = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let pressure_alt = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let temperature = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let fields_updated = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let id = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    time_usec,
    xacc,
    yacc,
    zacc,
    xgyro,
    ygyro,
    zgyro,
    xmag,
    ymag,
    zmag,
    abs_pressure,
    diff_pressure,
    pressure_alt,
    temperature,
    fields_updated,
    id,
  })
}

///|
/// File transfer protocol message: https://mavlink.io/en/services/ftp.html.
/// - MAVLink Message `FILE_TRANSFER_PROTOCOL` (ID: 110, CRC_EXTRA: 84, base_len: 254B, max_len: 254B)
pub(all) struct FileTransferProtocol {
  target_network : Byte
  target_system : Byte
  target_component : Byte
  payload : FixedArray[Byte]
} derive(Eq, Debug)

///|
pub extend FileTransferProtocol with Eq::{not_equal, equal}

///|
pub extend FileTransferProtocol with @debug.Debug::{to_repr}

///|
pub fn FileTransferProtocol::msg_id() -> UInt32 {
  110U
}

///|
pub fn FileTransferProtocol::crc_extra() -> Byte {
  b'\x54'
}

///|
pub fn FileTransferProtocol::base_payload_len() -> Int32 {
  254
}

///|
pub fn FileTransferProtocol::max_payload_len() -> Int32 {
  254
}

///|
/// Serialize `FileTransferProtocol` into wire-ordered little-endian payload bytes.
pub fn FileTransferProtocol::encode_payload(
  self : FileTransferProtocol,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=254)
  writer_.write_uint8(self.target_network)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  for idx_ = 0; idx_ < 251; idx_ = idx_ + 1 {
    let elem_ = if idx_ < self.payload.length() {
      self.payload[idx_]
    } else {
      b'\x00'
    }
    writer_.write_uint8(elem_)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `FileTransferProtocol` from wire-ordered little-endian payload bytes.
pub fn FileTransferProtocol::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[FileTransferProtocol, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let target_network = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let payload = FixedArray::make(251, b'\x00')
  for idx_ = 0; idx_ < 251; idx_ = idx_ + 1 {
    match reader_.read_uint8() {
      Ok(v) => payload[idx_] = v
      Err(e) => return Err(e)
    }
  }
  Ok({ target_network, target_system, target_component, payload, })
}

///|
/// Contains the home position.
/// - MAVLink Message `HOME_POSITION` (ID: 242, CRC_EXTRA: 104, base_len: 52B, max_len: 60B)
pub(all) struct HomePosition {
  latitude : Int32
  longitude : Int32
  altitude : Int32
  x : Float
  y : Float
  z : Float
  q : FixedArray[Float]
  approach_x : Float
  approach_y : Float
  approach_z : Float
  time_usec : UInt64
} derive(Eq, Debug)

///|
pub extend HomePosition with Eq::{not_equal, equal}

///|
pub extend HomePosition with @debug.Debug::{to_repr}

///|
pub fn HomePosition::msg_id() -> UInt32 {
  242U
}

///|
pub fn HomePosition::crc_extra() -> Byte {
  b'\x68'
}

///|
pub fn HomePosition::base_payload_len() -> Int32 {
  52
}

///|
pub fn HomePosition::max_payload_len() -> Int32 {
  60
}

///|
/// Serialize `HomePosition` into wire-ordered little-endian payload bytes.
pub fn HomePosition::encode_payload(
  self : HomePosition,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=60)
  writer_.write_int32(self.latitude)
  writer_.write_int32(self.longitude)
  writer_.write_int32(self.altitude)
  writer_.write_float(self.x)
  writer_.write_float(self.y)
  writer_.write_float(self.z)
  for idx_ = 0; idx_ < 4; idx_ = idx_ + 1 {
    let elem_ = if idx_ < self.q.length() {
      self.q[idx_]
    } else {
      (0.0 : Float)
    }
    writer_.write_float(elem_)
  }
  writer_.write_float(self.approach_x)
  writer_.write_float(self.approach_y)
  writer_.write_float(self.approach_z)
  if v2 {
    writer_.write_uint64(self.time_usec)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `HomePosition` from wire-ordered little-endian payload bytes.
pub fn HomePosition::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[HomePosition, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let latitude = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let longitude = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let altitude = match reader_.read_int32() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let x = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let y = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let z = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let q = FixedArray::make(4, (0.0 : Float))
  for idx_ = 0; idx_ < 4; idx_ = idx_ + 1 {
    match reader_.read_float() {
      Ok(v) => q[idx_] = v
      Err(e) => return Err(e)
    }
  }
  let approach_x = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let approach_y = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let approach_z = match reader_.read_float() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  reader_.zero_extend = true
  let time_usec = match reader_.read_uint64() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({
    latitude,
    longitude,
    altitude,
    x,
    y,
    z,
    q,
    approach_x,
    approach_y,
    approach_z,
    time_usec,
  })
}

///|
/// A message containing logged data (requires 24-bit MAVLink v2 message ID).
/// - MAVLink Message `LOGGING_DATA` (ID: 266, CRC_EXTRA: 193, base_len: 255B, max_len: 255B)
pub(all) struct LoggingData {
  target_system : Byte
  target_component : Byte
  sequence : UInt32
  length : Byte
  first_message_offset : Byte
  data : FixedArray[Byte]
} derive(Eq, Debug)

///|
pub extend LoggingData with Eq::{not_equal, equal}

///|
pub extend LoggingData with @debug.Debug::{to_repr}

///|
pub fn LoggingData::msg_id() -> UInt32 {
  266U
}

///|
pub fn LoggingData::crc_extra() -> Byte {
  b'\xC1'
}

///|
pub fn LoggingData::base_payload_len() -> Int32 {
  255
}

///|
pub fn LoggingData::max_payload_len() -> Int32 {
  255
}

///|
/// Serialize `LoggingData` into wire-ordered little-endian payload bytes.
pub fn LoggingData::encode_payload(
  self : LoggingData,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=255)
  writer_.write_uint16(self.sequence)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.write_uint8(self.length)
  writer_.write_uint8(self.first_message_offset)
  for idx_ = 0; idx_ < 249; idx_ = idx_ + 1 {
    let elem_ = if idx_ < self.data.length() {
      self.data[idx_]
    } else {
      b'\x00'
    }
    writer_.write_uint8(elem_)
  }
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `LoggingData` from wire-ordered little-endian payload bytes.
pub fn LoggingData::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[LoggingData, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let sequence = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let length = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let first_message_offset = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let data = FixedArray::make(249, b'\x00')
  for idx_ = 0; idx_ < 249; idx_ = idx_ + 1 {
    match reader_.read_uint8() {
      Ok(v) => data[idx_] = v
      Err(e) => return Err(e)
    }
  }
  Ok({
    target_system,
    target_component,
    sequence,
    length,
    first_message_offset,
    data,
  })
}

///|
/// Request to read the value of a parameter with either the param_id string id or param_index.
/// - MAVLink Message `PARAM_EXT_REQUEST_READ` (ID: 320, CRC_EXTRA: 243, base_len: 20B, max_len: 20B)
pub(all) struct ParamExtRequestRead {
  target_system : Byte
  target_component : Byte
  param_id : String
  param_index : Int32
} derive(Eq, Debug)

///|
pub extend ParamExtRequestRead with Eq::{not_equal, equal}

///|
pub extend ParamExtRequestRead with @debug.Debug::{to_repr}

///|
pub fn ParamExtRequestRead::msg_id() -> UInt32 {
  320U
}

///|
pub fn ParamExtRequestRead::crc_extra() -> Byte {
  b'\xF3'
}

///|
pub fn ParamExtRequestRead::base_payload_len() -> Int32 {
  20
}

///|
pub fn ParamExtRequestRead::max_payload_len() -> Int32 {
  20
}

///|
/// Serialize `ParamExtRequestRead` into wire-ordered little-endian payload bytes.
pub fn ParamExtRequestRead::encode_payload(
  self : ParamExtRequestRead,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=20)
  writer_.write_int16(self.param_index)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.write_char_array(self.param_id, 16)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `ParamExtRequestRead` from wire-ordered little-endian payload bytes.
pub fn ParamExtRequestRead::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[ParamExtRequestRead, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let param_index = match reader_.read_int16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_id = match reader_.read_char_array(16) {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, param_id, param_index, })
}

///|
/// Request all parameters of this component.
/// - MAVLink Message `PARAM_EXT_REQUEST_LIST` (ID: 321, CRC_EXTRA: 88, base_len: 2B, max_len: 2B)
pub(all) struct ParamExtRequestList {
  target_system : Byte
  target_component : Byte
} derive(Eq, Debug)

///|
pub extend ParamExtRequestList with Eq::{not_equal, equal}

///|
pub extend ParamExtRequestList with @debug.Debug::{to_repr}

///|
pub fn ParamExtRequestList::msg_id() -> UInt32 {
  321U
}

///|
pub fn ParamExtRequestList::crc_extra() -> Byte {
  b'\x58'
}

///|
pub fn ParamExtRequestList::base_payload_len() -> Int32 {
  2
}

///|
pub fn ParamExtRequestList::max_payload_len() -> Int32 {
  2
}

///|
/// Serialize `ParamExtRequestList` into wire-ordered little-endian payload bytes.
pub fn ParamExtRequestList::encode_payload(
  self : ParamExtRequestList,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=2)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `ParamExtRequestList` from wire-ordered little-endian payload bytes.
pub fn ParamExtRequestList::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[ParamExtRequestList, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, })
}

///|
/// Emit the value of a parameter.
/// - MAVLink Message `PARAM_EXT_VALUE` (ID: 322, CRC_EXTRA: 243, base_len: 149B, max_len: 149B)
pub(all) struct ParamExtValue {
  param_id : String
  param_value : String
  param_type : Byte
  param_count : UInt32
  param_index : UInt32
} derive(Eq, Debug)

///|
pub extend ParamExtValue with Eq::{not_equal, equal}

///|
pub extend ParamExtValue with @debug.Debug::{to_repr}

///|
pub fn ParamExtValue::msg_id() -> UInt32 {
  322U
}

///|
pub fn ParamExtValue::crc_extra() -> Byte {
  b'\xF3'
}

///|
pub fn ParamExtValue::base_payload_len() -> Int32 {
  149
}

///|
pub fn ParamExtValue::max_payload_len() -> Int32 {
  149
}

///|
/// Serialize `ParamExtValue` into wire-ordered little-endian payload bytes.
pub fn ParamExtValue::encode_payload(
  self : ParamExtValue,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=149)
  writer_.write_uint16(self.param_count)
  writer_.write_uint16(self.param_index)
  writer_.write_char_array(self.param_id, 16)
  writer_.write_char_array(self.param_value, 128)
  writer_.write_uint8(self.param_type)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `ParamExtValue` from wire-ordered little-endian payload bytes.
pub fn ParamExtValue::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[ParamExtValue, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let param_count = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_index = match reader_.read_uint16() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_id = match reader_.read_char_array(16) {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_value = match reader_.read_char_array(128) {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ param_id, param_value, param_type, param_count, param_index, })
}

///|
/// Set a parameter value.
/// - MAVLink Message `PARAM_EXT_SET` (ID: 323, CRC_EXTRA: 78, base_len: 147B, max_len: 147B)
pub(all) struct ParamExtSet {
  target_system : Byte
  target_component : Byte
  param_id : String
  param_value : String
  param_type : Byte
} derive(Eq, Debug)

///|
pub extend ParamExtSet with Eq::{not_equal, equal}

///|
pub extend ParamExtSet with @debug.Debug::{to_repr}

///|
pub fn ParamExtSet::msg_id() -> UInt32 {
  323U
}

///|
pub fn ParamExtSet::crc_extra() -> Byte {
  b'\x4E'
}

///|
pub fn ParamExtSet::base_payload_len() -> Int32 {
  147
}

///|
pub fn ParamExtSet::max_payload_len() -> Int32 {
  147
}

///|
/// Serialize `ParamExtSet` into wire-ordered little-endian payload bytes.
pub fn ParamExtSet::encode_payload(
  self : ParamExtSet,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=147)
  writer_.write_uint8(self.target_system)
  writer_.write_uint8(self.target_component)
  writer_.write_char_array(self.param_id, 16)
  writer_.write_char_array(self.param_value, 128)
  writer_.write_uint8(self.param_type)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `ParamExtSet` from wire-ordered little-endian payload bytes.
pub fn ParamExtSet::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[ParamExtSet, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let target_system = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let target_component = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_id = match reader_.read_char_array(16) {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_value = match reader_.read_char_array(128) {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ target_system, target_component, param_id, param_value, param_type, })
}

///|
/// Response from a PARAM_EXT_SET message.
/// - MAVLink Message `PARAM_EXT_ACK` (ID: 324, CRC_EXTRA: 132, base_len: 146B, max_len: 146B)
pub(all) struct ParamExtAck {
  param_id : String
  param_value : String
  param_type : Byte
  param_result : Byte
} derive(Eq, Debug)

///|
pub extend ParamExtAck with Eq::{not_equal, equal}

///|
pub extend ParamExtAck with @debug.Debug::{to_repr}

///|
pub fn ParamExtAck::msg_id() -> UInt32 {
  324U
}

///|
pub fn ParamExtAck::crc_extra() -> Byte {
  b'\x84'
}

///|
pub fn ParamExtAck::base_payload_len() -> Int32 {
  146
}

///|
pub fn ParamExtAck::max_payload_len() -> Int32 {
  146
}

///|
/// Serialize `ParamExtAck` into wire-ordered little-endian payload bytes.
pub fn ParamExtAck::encode_payload(
  self : ParamExtAck,
  v2~ : Bool = true,
) -> Bytes {
  let writer_ = PayloadWriter::new(capacity=146)
  writer_.write_char_array(self.param_id, 16)
  writer_.write_char_array(self.param_value, 128)
  writer_.write_uint8(self.param_type)
  writer_.write_uint8(self.param_result)
  writer_.to_wire_bytes(truncate_zeros=v2)
}

///|
/// Deserialize `ParamExtAck` from wire-ordered little-endian payload bytes.
pub fn ParamExtAck::decode_payload(
  payload_ : Bytes,
  v2~ : Bool = true,
) -> Result[ParamExtAck, MavError] {
  let reader_ = PayloadReader::new(payload_, zero_extend=v2)
  let param_id = match reader_.read_char_array(16) {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_value = match reader_.read_char_array(128) {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_type = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  let param_result = match reader_.read_uint8() {
    Ok(v) => v
    Err(e) => return Err(e)
  }
  Ok({ param_id, param_value, param_type, param_result, })
}

///|
/// Look up the precomputed `CRC_EXTRA` byte for a known MAVLink message ID.
pub fn lookup_message_crc_extra(msgid : UInt32) -> Byte? {
  match msgid {
    0U => Some(Heartbeat::crc_extra())
    1U => Some(SysStatus::crc_extra())
    2U => Some(SystemTime::crc_extra())
    4U => Some(Ping::crc_extra())
    11U => Some(SetMode::crc_extra())
    20U => Some(ParamRequestRead::crc_extra())
    21U => Some(ParamRequestList::crc_extra())
    22U => Some(ParamValue::crc_extra())
    23U => Some(ParamSet::crc_extra())
    24U => Some(GpsRawInt::crc_extra())
    26U => Some(ScaledImu::crc_extra())
    27U => Some(RawImu::crc_extra())
    29U => Some(ScaledPressure::crc_extra())
    30U => Some(Attitude::crc_extra())
    31U => Some(AttitudeQuaternion::crc_extra())
    32U => Some(LocalPositionNed::crc_extra())
    33U => Some(GlobalPositionInt::crc_extra())
    35U => Some(RcChannelsRaw::crc_extra())
    36U => Some(ServoOutputRaw::crc_extra())
    40U => Some(MissionRequest::crc_extra())
    41U => Some(MissionSetCurrent::crc_extra())
    42U => Some(MissionCurrent::crc_extra())
    43U => Some(MissionRequestList::crc_extra())
    44U => Some(MissionCount::crc_extra())
    45U => Some(MissionClearAll::crc_extra())
    46U => Some(MissionItemReached::crc_extra())
    47U => Some(MissionAck::crc_extra())
    51U => Some(MissionRequestInt::crc_extra())
    65U => Some(RcChannels::crc_extra())
    69U => Some(ManualControl::crc_extra())
    73U => Some(MissionItemInt::crc_extra())
    74U => Some(VfrHud::crc_extra())
    75U => Some(CommandInt::crc_extra())
    76U => Some(CommandLong::crc_extra())
    77U => Some(CommandAck::crc_extra())
    80U => Some(CommandCancel::crc_extra())
    82U => Some(SetAttitudeTarget::crc_extra())
    111U => Some(Timesync::crc_extra())
    132U => Some(DistanceSensor::crc_extra())
    147U => Some(BatteryStatus::crc_extra())
    148U => Some(AutopilotVersion::crc_extra())
    245U => Some(ExtendedSysState::crc_extra())
    253U => Some(Statustext::crc_extra())
    254U => Some(MavDebug::crc_extra())
    268U => Some(LoggingAck::crc_extra())
    38U => Some(MissionWritePartialList::crc_extra())
    39U => Some(MissionItem::crc_extra())
    83U => Some(AttitudeTarget::crc_extra())
    84U => Some(SetPositionTargetLocalNed::crc_extra())
    85U => Some(PositionTargetLocalNed::crc_extra())
    100U => Some(OpticalFlow::crc_extra())
    105U => Some(HighresImu::crc_extra())
    110U => Some(FileTransferProtocol::crc_extra())
    242U => Some(HomePosition::crc_extra())
    266U => Some(LoggingData::crc_extra())
    320U => Some(ParamExtRequestRead::crc_extra())
    321U => Some(ParamExtRequestList::crc_extra())
    322U => Some(ParamExtValue::crc_extra())
    323U => Some(ParamExtSet::crc_extra())
    324U => Some(ParamExtAck::crc_extra())
    _ => None
  }
}

///|
/// Look up the official MAVLink message name for a known message ID.
pub fn lookup_message_name(msgid : UInt32) -> String? {
  match msgid {
    0U => Some("HEARTBEAT")
    1U => Some("SYS_STATUS")
    2U => Some("SYSTEM_TIME")
    4U => Some("PING")
    11U => Some("SET_MODE")
    20U => Some("PARAM_REQUEST_READ")
    21U => Some("PARAM_REQUEST_LIST")
    22U => Some("PARAM_VALUE")
    23U => Some("PARAM_SET")
    24U => Some("GPS_RAW_INT")
    26U => Some("SCALED_IMU")
    27U => Some("RAW_IMU")
    29U => Some("SCALED_PRESSURE")
    30U => Some("ATTITUDE")
    31U => Some("ATTITUDE_QUATERNION")
    32U => Some("LOCAL_POSITION_NED")
    33U => Some("GLOBAL_POSITION_INT")
    35U => Some("RC_CHANNELS_RAW")
    36U => Some("SERVO_OUTPUT_RAW")
    40U => Some("MISSION_REQUEST")
    41U => Some("MISSION_SET_CURRENT")
    42U => Some("MISSION_CURRENT")
    43U => Some("MISSION_REQUEST_LIST")
    44U => Some("MISSION_COUNT")
    45U => Some("MISSION_CLEAR_ALL")
    46U => Some("MISSION_ITEM_REACHED")
    47U => Some("MISSION_ACK")
    51U => Some("MISSION_REQUEST_INT")
    65U => Some("RC_CHANNELS")
    69U => Some("MANUAL_CONTROL")
    73U => Some("MISSION_ITEM_INT")
    74U => Some("VFR_HUD")
    75U => Some("COMMAND_INT")
    76U => Some("COMMAND_LONG")
    77U => Some("COMMAND_ACK")
    80U => Some("COMMAND_CANCEL")
    82U => Some("SET_ATTITUDE_TARGET")
    111U => Some("TIMESYNC")
    132U => Some("DISTANCE_SENSOR")
    147U => Some("BATTERY_STATUS")
    148U => Some("AUTOPILOT_VERSION")
    245U => Some("EXTENDED_SYS_STATE")
    253U => Some("STATUSTEXT")
    254U => Some("DEBUG")
    268U => Some("LOGGING_ACK")
    38U => Some("MISSION_WRITE_PARTIAL_LIST")
    39U => Some("MISSION_ITEM")
    83U => Some("ATTITUDE_TARGET")
    84U => Some("SET_POSITION_TARGET_LOCAL_NED")
    85U => Some("POSITION_TARGET_LOCAL_NED")
    100U => Some("OPTICAL_FLOW")
    105U => Some("HIGHRES_IMU")
    110U => Some("FILE_TRANSFER_PROTOCOL")
    242U => Some("HOME_POSITION")
    266U => Some("LOGGING_DATA")
    320U => Some("PARAM_EXT_REQUEST_READ")
    321U => Some("PARAM_EXT_REQUEST_LIST")
    322U => Some("PARAM_EXT_VALUE")
    323U => Some("PARAM_EXT_SET")
    324U => Some("PARAM_EXT_ACK")
    _ => None
  }
}

///|
/// Unified top-level MAVLink dialect message sum type.
pub(all) enum MavMessage {
  MsgHeartbeat(Heartbeat)
  MsgSysStatus(SysStatus)
  MsgSystemTime(SystemTime)
  MsgPing(Ping)
  MsgSetMode(SetMode)
  MsgParamRequestRead(ParamRequestRead)
  MsgParamRequestList(ParamRequestList)
  MsgParamValue(ParamValue)
  MsgParamSet(ParamSet)
  MsgGpsRawInt(GpsRawInt)
  MsgScaledImu(ScaledImu)
  MsgRawImu(RawImu)
  MsgScaledPressure(ScaledPressure)
  MsgAttitude(Attitude)
  MsgAttitudeQuaternion(AttitudeQuaternion)
  MsgLocalPositionNed(LocalPositionNed)
  MsgGlobalPositionInt(GlobalPositionInt)
  MsgRcChannelsRaw(RcChannelsRaw)
  MsgServoOutputRaw(ServoOutputRaw)
  MsgMissionRequest(MissionRequest)
  MsgMissionSetCurrent(MissionSetCurrent)
  MsgMissionCurrent(MissionCurrent)
  MsgMissionRequestList(MissionRequestList)
  MsgMissionCount(MissionCount)
  MsgMissionClearAll(MissionClearAll)
  MsgMissionItemReached(MissionItemReached)
  MsgMissionAck(MissionAck)
  MsgMissionRequestInt(MissionRequestInt)
  MsgRcChannels(RcChannels)
  MsgManualControl(ManualControl)
  MsgMissionItemInt(MissionItemInt)
  MsgVfrHud(VfrHud)
  MsgCommandInt(CommandInt)
  MsgCommandLong(CommandLong)
  MsgCommandAck(CommandAck)
  MsgCommandCancel(CommandCancel)
  MsgSetAttitudeTarget(SetAttitudeTarget)
  MsgTimesync(Timesync)
  MsgDistanceSensor(DistanceSensor)
  MsgBatteryStatus(BatteryStatus)
  MsgAutopilotVersion(AutopilotVersion)
  MsgExtendedSysState(ExtendedSysState)
  MsgStatustext(Statustext)
  MsgMavDebug(MavDebug)
  MsgLoggingAck(LoggingAck)
  MsgMissionWritePartialList(MissionWritePartialList)
  MsgMissionItem(MissionItem)
  MsgAttitudeTarget(AttitudeTarget)
  MsgSetPositionTargetLocalNed(SetPositionTargetLocalNed)
  MsgPositionTargetLocalNed(PositionTargetLocalNed)
  MsgOpticalFlow(OpticalFlow)
  MsgHighresImu(HighresImu)
  MsgFileTransferProtocol(FileTransferProtocol)
  MsgHomePosition(HomePosition)
  MsgLoggingData(LoggingData)
  MsgParamExtRequestRead(ParamExtRequestRead)
  MsgParamExtRequestList(ParamExtRequestList)
  MsgParamExtValue(ParamExtValue)
  MsgParamExtSet(ParamExtSet)
  MsgParamExtAck(ParamExtAck)
} derive(Eq, Debug)

///|
pub extend MavMessage with Eq::{not_equal, equal}

///|
pub extend MavMessage with @debug.Debug::{to_repr}

///|
/// Return the numeric MAVLink message ID of `self`.
pub fn MavMessage::msg_id(self : MavMessage) -> UInt32 {
  match self {
    MsgHeartbeat(_) => 0U
    MsgSysStatus(_) => 1U
    MsgSystemTime(_) => 2U
    MsgPing(_) => 4U
    MsgSetMode(_) => 11U
    MsgParamRequestRead(_) => 20U
    MsgParamRequestList(_) => 21U
    MsgParamValue(_) => 22U
    MsgParamSet(_) => 23U
    MsgGpsRawInt(_) => 24U
    MsgScaledImu(_) => 26U
    MsgRawImu(_) => 27U
    MsgScaledPressure(_) => 29U
    MsgAttitude(_) => 30U
    MsgAttitudeQuaternion(_) => 31U
    MsgLocalPositionNed(_) => 32U
    MsgGlobalPositionInt(_) => 33U
    MsgRcChannelsRaw(_) => 35U
    MsgServoOutputRaw(_) => 36U
    MsgMissionRequest(_) => 40U
    MsgMissionSetCurrent(_) => 41U
    MsgMissionCurrent(_) => 42U
    MsgMissionRequestList(_) => 43U
    MsgMissionCount(_) => 44U
    MsgMissionClearAll(_) => 45U
    MsgMissionItemReached(_) => 46U
    MsgMissionAck(_) => 47U
    MsgMissionRequestInt(_) => 51U
    MsgRcChannels(_) => 65U
    MsgManualControl(_) => 69U
    MsgMissionItemInt(_) => 73U
    MsgVfrHud(_) => 74U
    MsgCommandInt(_) => 75U
    MsgCommandLong(_) => 76U
    MsgCommandAck(_) => 77U
    MsgCommandCancel(_) => 80U
    MsgSetAttitudeTarget(_) => 82U
    MsgTimesync(_) => 111U
    MsgDistanceSensor(_) => 132U
    MsgBatteryStatus(_) => 147U
    MsgAutopilotVersion(_) => 148U
    MsgExtendedSysState(_) => 245U
    MsgStatustext(_) => 253U
    MsgMavDebug(_) => 254U
    MsgLoggingAck(_) => 268U
    MsgMissionWritePartialList(_) => 38U
    MsgMissionItem(_) => 39U
    MsgAttitudeTarget(_) => 83U
    MsgSetPositionTargetLocalNed(_) => 84U
    MsgPositionTargetLocalNed(_) => 85U
    MsgOpticalFlow(_) => 100U
    MsgHighresImu(_) => 105U
    MsgFileTransferProtocol(_) => 110U
    MsgHomePosition(_) => 242U
    MsgLoggingData(_) => 266U
    MsgParamExtRequestRead(_) => 320U
    MsgParamExtRequestList(_) => 321U
    MsgParamExtValue(_) => 322U
    MsgParamExtSet(_) => 323U
    MsgParamExtAck(_) => 324U
  }
}

///|
/// Return the official MAVLink message name of `self`.
pub fn MavMessage::msg_name(self : MavMessage) -> String {
  match self {
    MsgHeartbeat(_) => "HEARTBEAT"
    MsgSysStatus(_) => "SYS_STATUS"
    MsgSystemTime(_) => "SYSTEM_TIME"
    MsgPing(_) => "PING"
    MsgSetMode(_) => "SET_MODE"
    MsgParamRequestRead(_) => "PARAM_REQUEST_READ"
    MsgParamRequestList(_) => "PARAM_REQUEST_LIST"
    MsgParamValue(_) => "PARAM_VALUE"
    MsgParamSet(_) => "PARAM_SET"
    MsgGpsRawInt(_) => "GPS_RAW_INT"
    MsgScaledImu(_) => "SCALED_IMU"
    MsgRawImu(_) => "RAW_IMU"
    MsgScaledPressure(_) => "SCALED_PRESSURE"
    MsgAttitude(_) => "ATTITUDE"
    MsgAttitudeQuaternion(_) => "ATTITUDE_QUATERNION"
    MsgLocalPositionNed(_) => "LOCAL_POSITION_NED"
    MsgGlobalPositionInt(_) => "GLOBAL_POSITION_INT"
    MsgRcChannelsRaw(_) => "RC_CHANNELS_RAW"
    MsgServoOutputRaw(_) => "SERVO_OUTPUT_RAW"
    MsgMissionRequest(_) => "MISSION_REQUEST"
    MsgMissionSetCurrent(_) => "MISSION_SET_CURRENT"
    MsgMissionCurrent(_) => "MISSION_CURRENT"
    MsgMissionRequestList(_) => "MISSION_REQUEST_LIST"
    MsgMissionCount(_) => "MISSION_COUNT"
    MsgMissionClearAll(_) => "MISSION_CLEAR_ALL"
    MsgMissionItemReached(_) => "MISSION_ITEM_REACHED"
    MsgMissionAck(_) => "MISSION_ACK"
    MsgMissionRequestInt(_) => "MISSION_REQUEST_INT"
    MsgRcChannels(_) => "RC_CHANNELS"
    MsgManualControl(_) => "MANUAL_CONTROL"
    MsgMissionItemInt(_) => "MISSION_ITEM_INT"
    MsgVfrHud(_) => "VFR_HUD"
    MsgCommandInt(_) => "COMMAND_INT"
    MsgCommandLong(_) => "COMMAND_LONG"
    MsgCommandAck(_) => "COMMAND_ACK"
    MsgCommandCancel(_) => "COMMAND_CANCEL"
    MsgSetAttitudeTarget(_) => "SET_ATTITUDE_TARGET"
    MsgTimesync(_) => "TIMESYNC"
    MsgDistanceSensor(_) => "DISTANCE_SENSOR"
    MsgBatteryStatus(_) => "BATTERY_STATUS"
    MsgAutopilotVersion(_) => "AUTOPILOT_VERSION"
    MsgExtendedSysState(_) => "EXTENDED_SYS_STATE"
    MsgStatustext(_) => "STATUSTEXT"
    MsgMavDebug(_) => "DEBUG"
    MsgLoggingAck(_) => "LOGGING_ACK"
    MsgMissionWritePartialList(_) => "MISSION_WRITE_PARTIAL_LIST"
    MsgMissionItem(_) => "MISSION_ITEM"
    MsgAttitudeTarget(_) => "ATTITUDE_TARGET"
    MsgSetPositionTargetLocalNed(_) => "SET_POSITION_TARGET_LOCAL_NED"
    MsgPositionTargetLocalNed(_) => "POSITION_TARGET_LOCAL_NED"
    MsgOpticalFlow(_) => "OPTICAL_FLOW"
    MsgHighresImu(_) => "HIGHRES_IMU"
    MsgFileTransferProtocol(_) => "FILE_TRANSFER_PROTOCOL"
    MsgHomePosition(_) => "HOME_POSITION"
    MsgLoggingData(_) => "LOGGING_DATA"
    MsgParamExtRequestRead(_) => "PARAM_EXT_REQUEST_READ"
    MsgParamExtRequestList(_) => "PARAM_EXT_REQUEST_LIST"
    MsgParamExtValue(_) => "PARAM_EXT_VALUE"
    MsgParamExtSet(_) => "PARAM_EXT_SET"
    MsgParamExtAck(_) => "PARAM_EXT_ACK"
  }
}

///|
/// Return the `CRC_EXTRA` seed byte of `self`.
pub fn MavMessage::crc_extra(self : MavMessage) -> Byte {
  match self {
    MsgHeartbeat(_) => Heartbeat::crc_extra()
    MsgSysStatus(_) => SysStatus::crc_extra()
    MsgSystemTime(_) => SystemTime::crc_extra()
    MsgPing(_) => Ping::crc_extra()
    MsgSetMode(_) => SetMode::crc_extra()
    MsgParamRequestRead(_) => ParamRequestRead::crc_extra()
    MsgParamRequestList(_) => ParamRequestList::crc_extra()
    MsgParamValue(_) => ParamValue::crc_extra()
    MsgParamSet(_) => ParamSet::crc_extra()
    MsgGpsRawInt(_) => GpsRawInt::crc_extra()
    MsgScaledImu(_) => ScaledImu::crc_extra()
    MsgRawImu(_) => RawImu::crc_extra()
    MsgScaledPressure(_) => ScaledPressure::crc_extra()
    MsgAttitude(_) => Attitude::crc_extra()
    MsgAttitudeQuaternion(_) => AttitudeQuaternion::crc_extra()
    MsgLocalPositionNed(_) => LocalPositionNed::crc_extra()
    MsgGlobalPositionInt(_) => GlobalPositionInt::crc_extra()
    MsgRcChannelsRaw(_) => RcChannelsRaw::crc_extra()
    MsgServoOutputRaw(_) => ServoOutputRaw::crc_extra()
    MsgMissionRequest(_) => MissionRequest::crc_extra()
    MsgMissionSetCurrent(_) => MissionSetCurrent::crc_extra()
    MsgMissionCurrent(_) => MissionCurrent::crc_extra()
    MsgMissionRequestList(_) => MissionRequestList::crc_extra()
    MsgMissionCount(_) => MissionCount::crc_extra()
    MsgMissionClearAll(_) => MissionClearAll::crc_extra()
    MsgMissionItemReached(_) => MissionItemReached::crc_extra()
    MsgMissionAck(_) => MissionAck::crc_extra()
    MsgMissionRequestInt(_) => MissionRequestInt::crc_extra()
    MsgRcChannels(_) => RcChannels::crc_extra()
    MsgManualControl(_) => ManualControl::crc_extra()
    MsgMissionItemInt(_) => MissionItemInt::crc_extra()
    MsgVfrHud(_) => VfrHud::crc_extra()
    MsgCommandInt(_) => CommandInt::crc_extra()
    MsgCommandLong(_) => CommandLong::crc_extra()
    MsgCommandAck(_) => CommandAck::crc_extra()
    MsgCommandCancel(_) => CommandCancel::crc_extra()
    MsgSetAttitudeTarget(_) => SetAttitudeTarget::crc_extra()
    MsgTimesync(_) => Timesync::crc_extra()
    MsgDistanceSensor(_) => DistanceSensor::crc_extra()
    MsgBatteryStatus(_) => BatteryStatus::crc_extra()
    MsgAutopilotVersion(_) => AutopilotVersion::crc_extra()
    MsgExtendedSysState(_) => ExtendedSysState::crc_extra()
    MsgStatustext(_) => Statustext::crc_extra()
    MsgMavDebug(_) => MavDebug::crc_extra()
    MsgLoggingAck(_) => LoggingAck::crc_extra()
    MsgMissionWritePartialList(_) => MissionWritePartialList::crc_extra()
    MsgMissionItem(_) => MissionItem::crc_extra()
    MsgAttitudeTarget(_) => AttitudeTarget::crc_extra()
    MsgSetPositionTargetLocalNed(_) => SetPositionTargetLocalNed::crc_extra()
    MsgPositionTargetLocalNed(_) => PositionTargetLocalNed::crc_extra()
    MsgOpticalFlow(_) => OpticalFlow::crc_extra()
    MsgHighresImu(_) => HighresImu::crc_extra()
    MsgFileTransferProtocol(_) => FileTransferProtocol::crc_extra()
    MsgHomePosition(_) => HomePosition::crc_extra()
    MsgLoggingData(_) => LoggingData::crc_extra()
    MsgParamExtRequestRead(_) => ParamExtRequestRead::crc_extra()
    MsgParamExtRequestList(_) => ParamExtRequestList::crc_extra()
    MsgParamExtValue(_) => ParamExtValue::crc_extra()
    MsgParamExtSet(_) => ParamExtSet::crc_extra()
    MsgParamExtAck(_) => ParamExtAck::crc_extra()
  }
}

///|
/// Return the base (non-extension) payload length in bytes of `self`.
pub fn MavMessage::base_payload_len(self : MavMessage) -> Int32 {
  match self {
    MsgHeartbeat(_) => Heartbeat::base_payload_len()
    MsgSysStatus(_) => SysStatus::base_payload_len()
    MsgSystemTime(_) => SystemTime::base_payload_len()
    MsgPing(_) => Ping::base_payload_len()
    MsgSetMode(_) => SetMode::base_payload_len()
    MsgParamRequestRead(_) => ParamRequestRead::base_payload_len()
    MsgParamRequestList(_) => ParamRequestList::base_payload_len()
    MsgParamValue(_) => ParamValue::base_payload_len()
    MsgParamSet(_) => ParamSet::base_payload_len()
    MsgGpsRawInt(_) => GpsRawInt::base_payload_len()
    MsgScaledImu(_) => ScaledImu::base_payload_len()
    MsgRawImu(_) => RawImu::base_payload_len()
    MsgScaledPressure(_) => ScaledPressure::base_payload_len()
    MsgAttitude(_) => Attitude::base_payload_len()
    MsgAttitudeQuaternion(_) => AttitudeQuaternion::base_payload_len()
    MsgLocalPositionNed(_) => LocalPositionNed::base_payload_len()
    MsgGlobalPositionInt(_) => GlobalPositionInt::base_payload_len()
    MsgRcChannelsRaw(_) => RcChannelsRaw::base_payload_len()
    MsgServoOutputRaw(_) => ServoOutputRaw::base_payload_len()
    MsgMissionRequest(_) => MissionRequest::base_payload_len()
    MsgMissionSetCurrent(_) => MissionSetCurrent::base_payload_len()
    MsgMissionCurrent(_) => MissionCurrent::base_payload_len()
    MsgMissionRequestList(_) => MissionRequestList::base_payload_len()
    MsgMissionCount(_) => MissionCount::base_payload_len()
    MsgMissionClearAll(_) => MissionClearAll::base_payload_len()
    MsgMissionItemReached(_) => MissionItemReached::base_payload_len()
    MsgMissionAck(_) => MissionAck::base_payload_len()
    MsgMissionRequestInt(_) => MissionRequestInt::base_payload_len()
    MsgRcChannels(_) => RcChannels::base_payload_len()
    MsgManualControl(_) => ManualControl::base_payload_len()
    MsgMissionItemInt(_) => MissionItemInt::base_payload_len()
    MsgVfrHud(_) => VfrHud::base_payload_len()
    MsgCommandInt(_) => CommandInt::base_payload_len()
    MsgCommandLong(_) => CommandLong::base_payload_len()
    MsgCommandAck(_) => CommandAck::base_payload_len()
    MsgCommandCancel(_) => CommandCancel::base_payload_len()
    MsgSetAttitudeTarget(_) => SetAttitudeTarget::base_payload_len()
    MsgTimesync(_) => Timesync::base_payload_len()
    MsgDistanceSensor(_) => DistanceSensor::base_payload_len()
    MsgBatteryStatus(_) => BatteryStatus::base_payload_len()
    MsgAutopilotVersion(_) => AutopilotVersion::base_payload_len()
    MsgExtendedSysState(_) => ExtendedSysState::base_payload_len()
    MsgStatustext(_) => Statustext::base_payload_len()
    MsgMavDebug(_) => MavDebug::base_payload_len()
    MsgLoggingAck(_) => LoggingAck::base_payload_len()
    MsgMissionWritePartialList(_) => MissionWritePartialList::base_payload_len()
    MsgMissionItem(_) => MissionItem::base_payload_len()
    MsgAttitudeTarget(_) => AttitudeTarget::base_payload_len()
    MsgSetPositionTargetLocalNed(_) =>
      SetPositionTargetLocalNed::base_payload_len()
    MsgPositionTargetLocalNed(_) => PositionTargetLocalNed::base_payload_len()
    MsgOpticalFlow(_) => OpticalFlow::base_payload_len()
    MsgHighresImu(_) => HighresImu::base_payload_len()
    MsgFileTransferProtocol(_) => FileTransferProtocol::base_payload_len()
    MsgHomePosition(_) => HomePosition::base_payload_len()
    MsgLoggingData(_) => LoggingData::base_payload_len()
    MsgParamExtRequestRead(_) => ParamExtRequestRead::base_payload_len()
    MsgParamExtRequestList(_) => ParamExtRequestList::base_payload_len()
    MsgParamExtValue(_) => ParamExtValue::base_payload_len()
    MsgParamExtSet(_) => ParamExtSet::base_payload_len()
    MsgParamExtAck(_) => ParamExtAck::base_payload_len()
  }
}

///|
/// Return the maximum (v2 with extensions) payload length in bytes of `self`.
pub fn MavMessage::max_payload_len(self : MavMessage) -> Int32 {
  match self {
    MsgHeartbeat(_) => Heartbeat::max_payload_len()
    MsgSysStatus(_) => SysStatus::max_payload_len()
    MsgSystemTime(_) => SystemTime::max_payload_len()
    MsgPing(_) => Ping::max_payload_len()
    MsgSetMode(_) => SetMode::max_payload_len()
    MsgParamRequestRead(_) => ParamRequestRead::max_payload_len()
    MsgParamRequestList(_) => ParamRequestList::max_payload_len()
    MsgParamValue(_) => ParamValue::max_payload_len()
    MsgParamSet(_) => ParamSet::max_payload_len()
    MsgGpsRawInt(_) => GpsRawInt::max_payload_len()
    MsgScaledImu(_) => ScaledImu::max_payload_len()
    MsgRawImu(_) => RawImu::max_payload_len()
    MsgScaledPressure(_) => ScaledPressure::max_payload_len()
    MsgAttitude(_) => Attitude::max_payload_len()
    MsgAttitudeQuaternion(_) => AttitudeQuaternion::max_payload_len()
    MsgLocalPositionNed(_) => LocalPositionNed::max_payload_len()
    MsgGlobalPositionInt(_) => GlobalPositionInt::max_payload_len()
    MsgRcChannelsRaw(_) => RcChannelsRaw::max_payload_len()
    MsgServoOutputRaw(_) => ServoOutputRaw::max_payload_len()
    MsgMissionRequest(_) => MissionRequest::max_payload_len()
    MsgMissionSetCurrent(_) => MissionSetCurrent::max_payload_len()
    MsgMissionCurrent(_) => MissionCurrent::max_payload_len()
    MsgMissionRequestList(_) => MissionRequestList::max_payload_len()
    MsgMissionCount(_) => MissionCount::max_payload_len()
    MsgMissionClearAll(_) => MissionClearAll::max_payload_len()
    MsgMissionItemReached(_) => MissionItemReached::max_payload_len()
    MsgMissionAck(_) => MissionAck::max_payload_len()
    MsgMissionRequestInt(_) => MissionRequestInt::max_payload_len()
    MsgRcChannels(_) => RcChannels::max_payload_len()
    MsgManualControl(_) => ManualControl::max_payload_len()
    MsgMissionItemInt(_) => MissionItemInt::max_payload_len()
    MsgVfrHud(_) => VfrHud::max_payload_len()
    MsgCommandInt(_) => CommandInt::max_payload_len()
    MsgCommandLong(_) => CommandLong::max_payload_len()
    MsgCommandAck(_) => CommandAck::max_payload_len()
    MsgCommandCancel(_) => CommandCancel::max_payload_len()
    MsgSetAttitudeTarget(_) => SetAttitudeTarget::max_payload_len()
    MsgTimesync(_) => Timesync::max_payload_len()
    MsgDistanceSensor(_) => DistanceSensor::max_payload_len()
    MsgBatteryStatus(_) => BatteryStatus::max_payload_len()
    MsgAutopilotVersion(_) => AutopilotVersion::max_payload_len()
    MsgExtendedSysState(_) => ExtendedSysState::max_payload_len()
    MsgStatustext(_) => Statustext::max_payload_len()
    MsgMavDebug(_) => MavDebug::max_payload_len()
    MsgLoggingAck(_) => LoggingAck::max_payload_len()
    MsgMissionWritePartialList(_) => MissionWritePartialList::max_payload_len()
    MsgMissionItem(_) => MissionItem::max_payload_len()
    MsgAttitudeTarget(_) => AttitudeTarget::max_payload_len()
    MsgSetPositionTargetLocalNed(_) =>
      SetPositionTargetLocalNed::max_payload_len()
    MsgPositionTargetLocalNed(_) => PositionTargetLocalNed::max_payload_len()
    MsgOpticalFlow(_) => OpticalFlow::max_payload_len()
    MsgHighresImu(_) => HighresImu::max_payload_len()
    MsgFileTransferProtocol(_) => FileTransferProtocol::max_payload_len()
    MsgHomePosition(_) => HomePosition::max_payload_len()
    MsgLoggingData(_) => LoggingData::max_payload_len()
    MsgParamExtRequestRead(_) => ParamExtRequestRead::max_payload_len()
    MsgParamExtRequestList(_) => ParamExtRequestList::max_payload_len()
    MsgParamExtValue(_) => ParamExtValue::max_payload_len()
    MsgParamExtSet(_) => ParamExtSet::max_payload_len()
    MsgParamExtAck(_) => ParamExtAck::max_payload_len()
  }
}

///|
/// Encode `self` into a wire payload.
pub fn MavMessage::encode_payload(
  self : MavMessage,
  v2~ : Bool = true,
) -> Bytes {
  match self {
    MsgHeartbeat(m) => m.encode_payload(v2~)
    MsgSysStatus(m) => m.encode_payload(v2~)
    MsgSystemTime(m) => m.encode_payload(v2~)
    MsgPing(m) => m.encode_payload(v2~)
    MsgSetMode(m) => m.encode_payload(v2~)
    MsgParamRequestRead(m) => m.encode_payload(v2~)
    MsgParamRequestList(m) => m.encode_payload(v2~)
    MsgParamValue(m) => m.encode_payload(v2~)
    MsgParamSet(m) => m.encode_payload(v2~)
    MsgGpsRawInt(m) => m.encode_payload(v2~)
    MsgScaledImu(m) => m.encode_payload(v2~)
    MsgRawImu(m) => m.encode_payload(v2~)
    MsgScaledPressure(m) => m.encode_payload(v2~)
    MsgAttitude(m) => m.encode_payload(v2~)
    MsgAttitudeQuaternion(m) => m.encode_payload(v2~)
    MsgLocalPositionNed(m) => m.encode_payload(v2~)
    MsgGlobalPositionInt(m) => m.encode_payload(v2~)
    MsgRcChannelsRaw(m) => m.encode_payload(v2~)
    MsgServoOutputRaw(m) => m.encode_payload(v2~)
    MsgMissionRequest(m) => m.encode_payload(v2~)
    MsgMissionSetCurrent(m) => m.encode_payload(v2~)
    MsgMissionCurrent(m) => m.encode_payload(v2~)
    MsgMissionRequestList(m) => m.encode_payload(v2~)
    MsgMissionCount(m) => m.encode_payload(v2~)
    MsgMissionClearAll(m) => m.encode_payload(v2~)
    MsgMissionItemReached(m) => m.encode_payload(v2~)
    MsgMissionAck(m) => m.encode_payload(v2~)
    MsgMissionRequestInt(m) => m.encode_payload(v2~)
    MsgRcChannels(m) => m.encode_payload(v2~)
    MsgManualControl(m) => m.encode_payload(v2~)
    MsgMissionItemInt(m) => m.encode_payload(v2~)
    MsgVfrHud(m) => m.encode_payload(v2~)
    MsgCommandInt(m) => m.encode_payload(v2~)
    MsgCommandLong(m) => m.encode_payload(v2~)
    MsgCommandAck(m) => m.encode_payload(v2~)
    MsgCommandCancel(m) => m.encode_payload(v2~)
    MsgSetAttitudeTarget(m) => m.encode_payload(v2~)
    MsgTimesync(m) => m.encode_payload(v2~)
    MsgDistanceSensor(m) => m.encode_payload(v2~)
    MsgBatteryStatus(m) => m.encode_payload(v2~)
    MsgAutopilotVersion(m) => m.encode_payload(v2~)
    MsgExtendedSysState(m) => m.encode_payload(v2~)
    MsgStatustext(m) => m.encode_payload(v2~)
    MsgMavDebug(m) => m.encode_payload(v2~)
    MsgLoggingAck(m) => m.encode_payload(v2~)
    MsgMissionWritePartialList(m) => m.encode_payload(v2~)
    MsgMissionItem(m) => m.encode_payload(v2~)
    MsgAttitudeTarget(m) => m.encode_payload(v2~)
    MsgSetPositionTargetLocalNed(m) => m.encode_payload(v2~)
    MsgPositionTargetLocalNed(m) => m.encode_payload(v2~)
    MsgOpticalFlow(m) => m.encode_payload(v2~)
    MsgHighresImu(m) => m.encode_payload(v2~)
    MsgFileTransferProtocol(m) => m.encode_payload(v2~)
    MsgHomePosition(m) => m.encode_payload(v2~)
    MsgLoggingData(m) => m.encode_payload(v2~)
    MsgParamExtRequestRead(m) => m.encode_payload(v2~)
    MsgParamExtRequestList(m) => m.encode_payload(v2~)
    MsgParamExtValue(m) => m.encode_payload(v2~)
    MsgParamExtSet(m) => m.encode_payload(v2~)
    MsgParamExtAck(m) => m.encode_payload(v2~)
  }
}

///|
/// Encode `self` into a complete MAVLink v1 or v2 wire frame.
pub fn MavMessage::encode_to_frame(
  self : MavMessage,
  seq~ : Byte,
  sysid~ : Byte,
  compid~ : Byte,
  version~ : ProtocolVersion = V2,
  signing~ : SigningContext? = None,
) -> Result[(Bytes, MavFrame), MavError] {
  let is_v2 = version == V2
  let raw_payload = self.encode_payload(v2=is_v2)
  let header : MavHeader = {
    version,
    incompat_flags: b'\x00',
    compat_flags: b'\x00',
    seq,
    sysid,
    compid,
    msgid: self.msg_id(),
  }
  encode_frame(
    header,
    raw_payload,
    self.crc_extra(),
    truncate_v2_zeros=is_v2,
    signing~,
  )
}

///|
/// Decode a `MavMessage` from a verified `MavFrame`.
pub fn MavMessage::decode_from_frame(
  frame : MavFrame,
) -> Result[MavMessage, MavError] {
  let is_v2 = frame.header.version == V2
  match frame.header.msgid {
    0U =>
      match Heartbeat::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgHeartbeat(m))
        Err(e) => Err(e)
      }
    1U =>
      match SysStatus::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgSysStatus(m))
        Err(e) => Err(e)
      }
    2U =>
      match SystemTime::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgSystemTime(m))
        Err(e) => Err(e)
      }
    4U =>
      match Ping::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgPing(m))
        Err(e) => Err(e)
      }
    11U =>
      match SetMode::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgSetMode(m))
        Err(e) => Err(e)
      }
    20U =>
      match ParamRequestRead::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgParamRequestRead(m))
        Err(e) => Err(e)
      }
    21U =>
      match ParamRequestList::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgParamRequestList(m))
        Err(e) => Err(e)
      }
    22U =>
      match ParamValue::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgParamValue(m))
        Err(e) => Err(e)
      }
    23U =>
      match ParamSet::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgParamSet(m))
        Err(e) => Err(e)
      }
    24U =>
      match GpsRawInt::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgGpsRawInt(m))
        Err(e) => Err(e)
      }
    26U =>
      match ScaledImu::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgScaledImu(m))
        Err(e) => Err(e)
      }
    27U =>
      match RawImu::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgRawImu(m))
        Err(e) => Err(e)
      }
    29U =>
      match ScaledPressure::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgScaledPressure(m))
        Err(e) => Err(e)
      }
    30U =>
      match Attitude::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgAttitude(m))
        Err(e) => Err(e)
      }
    31U =>
      match AttitudeQuaternion::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgAttitudeQuaternion(m))
        Err(e) => Err(e)
      }
    32U =>
      match LocalPositionNed::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgLocalPositionNed(m))
        Err(e) => Err(e)
      }
    33U =>
      match GlobalPositionInt::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgGlobalPositionInt(m))
        Err(e) => Err(e)
      }
    35U =>
      match RcChannelsRaw::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgRcChannelsRaw(m))
        Err(e) => Err(e)
      }
    36U =>
      match ServoOutputRaw::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgServoOutputRaw(m))
        Err(e) => Err(e)
      }
    40U =>
      match MissionRequest::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgMissionRequest(m))
        Err(e) => Err(e)
      }
    41U =>
      match MissionSetCurrent::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgMissionSetCurrent(m))
        Err(e) => Err(e)
      }
    42U =>
      match MissionCurrent::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgMissionCurrent(m))
        Err(e) => Err(e)
      }
    43U =>
      match MissionRequestList::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgMissionRequestList(m))
        Err(e) => Err(e)
      }
    44U =>
      match MissionCount::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgMissionCount(m))
        Err(e) => Err(e)
      }
    45U =>
      match MissionClearAll::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgMissionClearAll(m))
        Err(e) => Err(e)
      }
    46U =>
      match MissionItemReached::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgMissionItemReached(m))
        Err(e) => Err(e)
      }
    47U =>
      match MissionAck::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgMissionAck(m))
        Err(e) => Err(e)
      }
    51U =>
      match MissionRequestInt::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgMissionRequestInt(m))
        Err(e) => Err(e)
      }
    65U =>
      match RcChannels::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgRcChannels(m))
        Err(e) => Err(e)
      }
    69U =>
      match ManualControl::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgManualControl(m))
        Err(e) => Err(e)
      }
    73U =>
      match MissionItemInt::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgMissionItemInt(m))
        Err(e) => Err(e)
      }
    74U =>
      match VfrHud::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgVfrHud(m))
        Err(e) => Err(e)
      }
    75U =>
      match CommandInt::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgCommandInt(m))
        Err(e) => Err(e)
      }
    76U =>
      match CommandLong::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgCommandLong(m))
        Err(e) => Err(e)
      }
    77U =>
      match CommandAck::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgCommandAck(m))
        Err(e) => Err(e)
      }
    80U =>
      match CommandCancel::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgCommandCancel(m))
        Err(e) => Err(e)
      }
    82U =>
      match SetAttitudeTarget::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgSetAttitudeTarget(m))
        Err(e) => Err(e)
      }
    111U =>
      match Timesync::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgTimesync(m))
        Err(e) => Err(e)
      }
    132U =>
      match DistanceSensor::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgDistanceSensor(m))
        Err(e) => Err(e)
      }
    147U =>
      match BatteryStatus::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgBatteryStatus(m))
        Err(e) => Err(e)
      }
    148U =>
      match AutopilotVersion::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgAutopilotVersion(m))
        Err(e) => Err(e)
      }
    245U =>
      match ExtendedSysState::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgExtendedSysState(m))
        Err(e) => Err(e)
      }
    253U =>
      match Statustext::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgStatustext(m))
        Err(e) => Err(e)
      }
    254U =>
      match MavDebug::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgMavDebug(m))
        Err(e) => Err(e)
      }
    268U =>
      match LoggingAck::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgLoggingAck(m))
        Err(e) => Err(e)
      }
    38U =>
      match MissionWritePartialList::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgMissionWritePartialList(m))
        Err(e) => Err(e)
      }
    39U =>
      match MissionItem::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgMissionItem(m))
        Err(e) => Err(e)
      }
    83U =>
      match AttitudeTarget::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgAttitudeTarget(m))
        Err(e) => Err(e)
      }
    84U =>
      match SetPositionTargetLocalNed::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgSetPositionTargetLocalNed(m))
        Err(e) => Err(e)
      }
    85U =>
      match PositionTargetLocalNed::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgPositionTargetLocalNed(m))
        Err(e) => Err(e)
      }
    100U =>
      match OpticalFlow::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgOpticalFlow(m))
        Err(e) => Err(e)
      }
    105U =>
      match HighresImu::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgHighresImu(m))
        Err(e) => Err(e)
      }
    110U =>
      match FileTransferProtocol::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgFileTransferProtocol(m))
        Err(e) => Err(e)
      }
    242U =>
      match HomePosition::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgHomePosition(m))
        Err(e) => Err(e)
      }
    266U =>
      match LoggingData::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgLoggingData(m))
        Err(e) => Err(e)
      }
    320U =>
      match ParamExtRequestRead::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgParamExtRequestRead(m))
        Err(e) => Err(e)
      }
    321U =>
      match ParamExtRequestList::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgParamExtRequestList(m))
        Err(e) => Err(e)
      }
    322U =>
      match ParamExtValue::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgParamExtValue(m))
        Err(e) => Err(e)
      }
    323U =>
      match ParamExtSet::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgParamExtSet(m))
        Err(e) => Err(e)
      }
    324U =>
      match ParamExtAck::decode_payload(frame.payload, v2=is_v2) {
        Ok(m) => Ok(MsgParamExtAck(m))
        Err(e) => Err(e)
      }
    other => Err(UnknownMessageId(other))
  }
}