Replace proto-based bambu_protocol with plain-Rust bambu_commands/
One file per command (get_version.rs, pushall.rs), each holding its request AND response together. CommandEnvelope (sequence_id + command) is the shared-fields piece every command embeds via #[serde(flatten)] — the 'inheritance' replacement for these structs, same composition idea as BambuGenericPrinter in bambu.rs, just expressed as a struct field instead of impl-block delegation. examples/bambu_commands_demo.rs round-trips both commands against Bambu's exact real JSON (from the original conversation) and confirms byte-for- byte matches, same as the removed proto version did — this replacement is behaviorally identical, just without protoc/build.rs in the loop.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
//! 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);
|
||||
}
|
||||
Reference in New Issue
Block a user