Display / Debug
Diagnostic only; not a stable wire or log schema. Do not treat either format as a protocol or long-term log contract.
Display currently equals Debug for generated decoders ({car} and
{car:?} print the same text). Prefer Debug in logs if you want that intent
to stay obvious when/if the two diverge later.
#![allow(unused)]
fn main() {
pub fn demo_display_debug(valid_car: &[u8]) -> Result<(), Box<dyn std::error::Error>> {
let car = CarDecoder::try_from(valid_car)?;
let display = format!("{car}");
let debug = format!("{car:#?}");
// Display is a compact one-liner; field names use the schema's camelCase.
assert!(display.contains("serialNumber: 1234"));
assert!(display.contains("modelYear: 2013"));
assert!(display.contains("available: true"));
assert!(display.contains(r#"code: A"#));
assert!(display.contains("manufacturer: \"Honda\""));
assert!(display.contains("model: \"Civic VTi\""));
assert!(display.contains("fuelFigures: ["));
assert!(display.contains("performanceFigures: ["));
assert!(display.contains(r#"activationCode: "abcdef""#));
// Pretty Debug ({:#?}) shows each field on its own line with indentation.
for expected in &[
"serialNumber: 1234",
"modelYear: 2013",
"available: true",
r#"manufacturer: "Honda""#,
r#"model: "Civic VTi""#,
r#"activationCode: "abcdef""#,
r#"usageDescription: "Urban""#,
"speed: 30",
"mpg: 35.9",
"octaneRating: 95",
] {
assert!(
debug.contains(expected),
"Debug missing: {expected}\n--- full debug ---\n{debug}"
);
}
// ── CarDomain DTO ───────────────────────────────────────────────────
// Owned, heap-allocated, serialisable snapshot of the full message tree.
// Generated by `with_domain_objects(DomainVarData::Strings)`.
let dto = CarDomain::try_from_decoder(car)?;
let dto_dbg = format!("{dto:#?}");
// DTO field names use Rust snake_case (different from wire decoder camelCase).
assert!(dto_dbg.contains("serial_number: 1234"));
assert!(dto_dbg.contains("model_year: 2013"));
assert!(dto_dbg.contains("available: true"));
assert!(dto_dbg.contains("fuel_figures: ["));
assert!(dto_dbg.contains(r#"usage_description: "Urban""#));
assert!(dto_dbg.contains(r#"manufacturer: "Honda""#));
assert!(dto_dbg.contains(r#"activation_code: "abcdef""#));
Ok(())
}
}
(This code comes from the sbe-feature-tour sample crate.)
Real output from the feature-tour Car (the CarDecoder that
demo_car_size_and_encode produces):
CarDecoder { serialNumber: 1234, modelYear: 2013, available: true, code: A, extras: sportsPack|cruiseControl, engine: Engine { capacity: 2000, numCylinders: 4, maxRpm: 9000, manufacturerCode: [49, 50, 51], fuel: "Petrol", efficiency: 0, boosterEnabled: F, booster: Booster { BoostType: TURBO, horsePower: 210 } }, fuelFigures: [CarFuelFiguresEntryDecoder { speed: 30, mpg: 35.9, usageDescription: "Urban" }, CarFuelFiguresEntryDecoder { speed: 60, mpg: 25.0, usageDescription: "Highway" }], performanceFigures: [CarPerformanceFiguresEntryDecoder { octaneRating: 95, acceleration: [CarPerformanceFiguresAccelerationEntryDecoder { mph: 30, seconds: 4.0 }, CarPerformanceFiguresAccelerationEntryDecoder { mph: 60, seconds: 7.5 }] }], manufacturer: "Honda", model: "Civic VTi", activationCode: "abcdef" }
Group entries print as nested structures, in wire order (fields, nested groups,
var data), and {:#?} indents them. An entry that fails to decode shows as its
DecodeError.
Truncated / incomplete buffers omit missing tails rather than panicking.
No compiled codec for the bytes? ergo-sbe-inspect reads them at run time
from the schema file and prints the same field names and leaf values, plus the
fields Display skips; containers differ on purpose
(Inspect bytes with no codec).