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:
2026-08-28 22:49:06 +00:00
parent 8e5d85202f
commit 166761479b
8 changed files with 145 additions and 78 deletions
+35
View File
@@ -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);
}
-24
View File
@@ -1,24 +0,0 @@
//! Run with: cargo run --example bambu_protocol_demo
//!
//! Proves the whole pipeline end to end: a message written in
//! continuum-schemas' proto/bambulab/v1/request.proto, compiled by prost
//! into a real Rust struct, wrapped in the hand-written BambuRequest enum,
//! and serialized by plain serde — no protobuf binary encoding involved,
//! since Bambu's actual wire format is JSON over MQTT.
use continuum_proxy::printer::BambuRequest;
use continuum_types::bambulab::v1::InfoCommand;
fn main() {
let request = BambuRequest::Info(InfoCommand {
sequence_id: "0".to_string(),
command: "get_version".to_string(),
});
let actual = serde_json::to_string(&request).unwrap();
let expected = r#"{"info":{"sequence_id":"0","command":"get_version"}}"#;
println!("generated: {actual}");
println!("Bambu's real wire format: {expected}");
println!("match: {}", actual == expected);
}