//! Run with: cargo run --example bambu_commands_demo //! //! Round-trips both commands against the exact JSON from Bambu's real //! protocol — proves the plain hand-written struct + serde approach //! matches byte for byte, same as the proto-based version did, with none //! of the build.rs ceremony. use continuum_proxy::printer::{CommandEnvelope, GetVersionRequest, GetVersionResponse, PushallRequest}; fn main() { // --- get_version request --- let req = GetVersionRequest { envelope: CommandEnvelope { sequence_id: "0".to_string(), command: "get_version".to_string() }, }; let actual = serde_json::to_string(&req).unwrap(); let expected = r#"{"sequence_id":"0","command":"get_version"}"#; println!("get_version request: {actual}"); println!("matches Bambu's shape: {}\n", actual == expected); // --- get_version response, deserialized from Bambu's real payload --- let real_response = r#"{"command":"get_version","module":[{"hw_ver":"","name":"ota","sn":"","sw_ver":"01.01.01.00"},{"hw_ver":"","name":"xm","sn":"","sw_ver":"00.00.00.00"}],"sequence_id":"0"}"#; let parsed: GetVersionResponse = serde_json::from_str(real_response).unwrap(); println!("get_version response parsed fine, no result/reason present: {parsed:#?}\n"); // --- pushall request --- let pushall = PushallRequest { envelope: CommandEnvelope { sequence_id: "0".to_string(), command: "pushall".to_string() }, version: 1, push_target: 1, }; let actual = serde_json::to_string(&pushall).unwrap(); let expected = r#"{"sequence_id":"0","command":"pushall","version":1,"push_target":1}"#; println!("pushall request: {actual}"); println!("matches Bambu's shape: {}", actual == expected); }