fly_ruler_proto_core 0.4.0

Protobuf UDP runtime and time-series state kernel for aerospace simulation
Documentation
// Generated protobuf module for the Fly Ruler wire schema.
//
// Generated by `core/build.rs` from `core/proto/fly_ruler.proto`.

#![allow(clippy::large_enum_variant)]
#![allow(missing_docs)]

include!(concat!(env!("OUT_DIR"), "/flyruler.rs"));

#[cfg(test)]
mod tests {
    use super::*;
    use prost::Message as ProstMessage;

    #[test]
    fn heartbeat_carries_client_uuid_roundtrip() {
        let msg = Message {
            envelope: Some(message::Envelope::Request(Request {
                id: Some(Uuid {
                    value: vec![0x12; 16],
                }),
                timestamp: 1.5,
                command: Some(RequestCommand {
                    kind: Some(request_command::Kind::Heartbeat(Heartbeat {
                        seq_num: 99,
                        client_uuid: Some(Uuid {
                            value: vec![0xab; 16],
                        }),
                    })),
                }),
            })),
        };

        let bytes = msg.encode_to_vec();
        let decoded = Message::decode(bytes.as_slice()).unwrap();
        let Some(message::Envelope::Request(req)) = decoded.envelope else {
            panic!("expected request envelope");
        };
        let Some(request_command::Kind::Heartbeat(hb)) = req.command.and_then(|c| c.kind) else {
            panic!("expected heartbeat command");
        };
        assert_eq!(hb.seq_num, 99);
        assert_eq!(hb.client_uuid.unwrap().value, vec![0xab; 16]);
    }

    #[test]
    fn aircraft_state_roundtrip_and_unknown_legacy_fields_are_ignored() {
        let state = AircraftState {
            derived: Some(DerivedState {
                ias: Some(45.0),
                cas: Some(46.0),
                mach: Some(0.14),
                ..Default::default()
            }),
            control_surfaces: Some(ControlSurfaceState {
                elevator_rad: Some(0.1),
                spoilers_ratio: Some(0.25),
                ..Default::default()
            }),
            propulsors: vec![PropulsorState {
                propulsor_id: "engine.left".to_string(),
                kind: PropulsorKind::Jet as i32,
                throttle_ratio: Some(0.7),
                rpm: Some(12_000.0),
                blade_pitch_rad: Some(0.2),
                thrust_newton: Some(1_500.0),
                torque_newton_meter: Some(250.0),
                index: Some(1),
            }],
            ..Default::default()
        };

        let decoded = AircraftState::decode(state.encode_to_vec().as_slice()).unwrap();
        let derived = decoded.derived.unwrap();
        assert_eq!(derived.mach, Some(0.14));
        assert_eq!(decoded.control_surfaces.unwrap().elevator_rad, Some(0.1));
        assert_eq!(decoded.propulsors[0].index, Some(1));
        assert_eq!(decoded.propulsors[0].throttle_ratio, Some(0.7));

        // Unknown legacy fields 6 and 8 are ignored while known fields still decode.
        let legacy_with_unknown_fields = [
            0x0a, 0x1b, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x11, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
            0x40, 0x32, 0x02, 0x08, 0x01, 0x42, 0x02, 0x08, 0x01,
        ];
        let legacy = AircraftState::decode(legacy_with_unknown_fields.as_slice()).unwrap();
        assert_eq!(legacy.position.unwrap().x, 1.0);
        assert!(legacy.control_surfaces.is_none());
        assert!(legacy.propulsors.is_empty());
    }
}