Wire InfoCommand through as one real, runnable example
BambuRequest::Info(InfoCommand) is now live (was commented out) — examples/bambu_protocol_demo.rs constructs one, serializes it, and prints it next to Bambu's real wire JSON for comparison. Run it and copy this exact shape (proto message -> use it here -> add an enum variant) for every other command.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
//! Bambu's real MQTT wire format: `{"info": {...}}`, `{"pushing": {...}}`,
|
||||
//! `{"print": {...}}` — one JSON object with a single key naming which
|
||||
//! command/report it is.
|
||||
//!
|
||||
//! Deliberately NOT modeled as a proto `oneof` for the top level — see the
|
||||
//! long comment in continuum-schemas/packages/rust-types/build.rs for why
|
||||
//! (short version: prost-build's field/variant attribute matching can't
|
||||
//! keep "the oneof field" and "the variants inside it" apart, so
|
||||
//! `#[serde(flatten)]` can't be scoped correctly and won't compile). This
|
||||
//! plain Rust enum sidesteps the problem entirely: serde's *default* enum
|
||||
//! representation already produces exactly `{"info": {...}}` with zero
|
||||
//! attributes needed.
|
||||
//!
|
||||
//! `Info` below is the one fully-wired example — run
|
||||
//! `cargo run --example bambu_protocol_demo` to see it actually produce
|
||||
//! Bambu's real wire JSON. Copy this exact shape for every other command:
|
||||
//! 1. Write the message in continuum-schemas' bambulab/v1/request.proto
|
||||
//! (or report.proto for a response).
|
||||
//! 2. `use` it up top, same as `InfoCommand` below.
|
||||
//! 3. Add one variant here, named to match Bambu's JSON key exactly
|
||||
//! (`#[serde(rename_all = "snake_case")]` on the enum handles simple
|
||||
//! cases automatically — a Rust variant `Pushing` becomes JSON key
|
||||
//! `"pushing"` for free; only reach for `#[serde(rename = "...")]` on
|
||||
//! a specific variant if the key doesn't snake_case cleanly from the
|
||||
//! Rust name).
|
||||
|
||||
use continuum_types::bambulab::v1::InfoCommand;
|
||||
|
||||
/// One request you can send to a Bambu printer. Grows by one variant per
|
||||
/// message you define in bambulab/v1/request.proto.
|
||||
#[derive(serde::Serialize, Debug)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum BambuRequest {
|
||||
Info(InfoCommand),
|
||||
// Pushing(PushingCommand),
|
||||
}
|
||||
|
||||
/// One report/response received from a Bambu printer. Same idea, the other
|
||||
/// direction — grows by one variant per message in bambulab/v1/report.proto.
|
||||
/// Empty for now: no response messages defined yet (InfoResponse is the
|
||||
/// natural first one — see the JSON example in bambu_protocol_demo.rs).
|
||||
#[derive(serde::Deserialize, Debug)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum BambuReport {}
|
||||
|
||||
// V1/V2 fork here once you know how much of the wire format actually
|
||||
// differs: if it's mostly the same shape, one BambuRequest/BambuReport
|
||||
// covering fields from both packages may be enough (some variants simply
|
||||
// unused on one generation); if the reports genuinely diverge, mirror this
|
||||
// file as bambu_protocol_v2.rs against continuum_types::bambulab::v2.
|
||||
@@ -29,10 +29,12 @@
|
||||
//! `tokio::spawn`, not yet).
|
||||
|
||||
mod bambu;
|
||||
mod bambu_protocol;
|
||||
mod klipper;
|
||||
mod prusa;
|
||||
|
||||
pub use bambu::{BambuGenericPrinter, BambuTls, BambuV1Printer, BambuV2Printer};
|
||||
pub use bambu_protocol::{BambuReport, BambuRequest};
|
||||
pub use klipper::KlipperPrinter;
|
||||
pub use prusa::{PrusaLinkPrinter, PrusaSerialPrinter};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user