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
+56
View File
@@ -0,0 +1,56 @@
//! Bambu's raw MQTT command/report structs — plain hand-written Rust +
//! serde, no protobuf. This data only ever needs to be understood by this
//! crate (raw vendor wire format, never crosses into TypeScript), and the
//! actual wire format is JSON over MQTT, not binary protobuf — protobuf's
//! codegen tooling kept fighting us for a payoff (cross-language codegen,
//! binary wire efficiency) that doesn't apply here at all. Proto stays in
//! continuum-schemas for continuum.v1, which is a schema we designed
//! ourselves and that both TS and Rust genuinely need.
//!
//! One file per command (`get_version.rs`, `pushall.rs`, ...) — each holds
//! its request AND response together, since they're conceptually one unit.
//! Copy `get_version.rs`'s shape for your next command.
mod get_version;
mod pushall;
pub use get_version::{GetVersionRequest, GetVersionResponse, ModuleInfo};
pub use pushall::{PushallRequest, PushallResponse};
/// Fields every Bambu command/response shares. This is the "inheritance"
/// replacement for these structs — composition, not extension: every
/// command below *has* one of these, embedded via `#[serde(flatten)]`
/// (which unwraps it onto the parent object at serialize/deserialize
/// time, so the JSON stays flat — no extra nesting), rather than
/// *extending* a base class. Exactly the same idea as `BambuGenericPrinter`
/// in `../bambu.rs`, just expressed with a struct field instead of a
/// struct-holding-a-struct in `impl` blocks.
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
pub struct CommandEnvelope {
pub sequence_id: String,
pub command: String,
}
/// One request you can send to a Bambu printer, keyed by Bambu's top-level
/// JSON category ("info", "pushing", ...). NOTE: that top-level key is a
/// *category*, not the specific command — `CommandEnvelope::command` is
/// what actually says which one ("get_version", "pushall", ...). Right
/// now each category maps to exactly one known command, one-to-one. If a
/// category ever needs a second command (e.g. "info" gaining something
/// besides get_version), that variant's payload becomes its own small
/// `#[serde(tag = "command")]` enum instead of a single struct — ask if
/// you get there and want a worked example.
#[derive(serde::Serialize, Debug)]
#[serde(rename_all = "snake_case")]
pub enum BambuRequest {
Info(GetVersionRequest),
Pushing(PushallRequest),
}
/// Same idea, the response direction.
#[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "snake_case")]
pub enum BambuReport {
Info(GetVersionResponse),
Pushing(PushallResponse),
}