buswatch-types
Core type definitions for the buswatch ecosystem.
This crate defines the canonical wire format for message bus metrics. All buswatch components use these types for serialization and deserialization.
Types
| Type | Description |
|---|---|
Snapshot |
Point-in-time view of all modules and their metrics |
ModuleMetrics |
Read and write metrics for a single module |
ReadMetrics |
Consumption metrics: count, backlog, pending duration, rate |
WriteMetrics |
Production metrics: count, pending duration, rate |
Microseconds |
Duration wrapper for consistent serialization |
SchemaVersion |
Version info for forward compatibility |
Usage
[]
= { = "0.1", = ["serde"] }
Building Snapshots
use Snapshot;
use Duration;
let snapshot = builder
.module
.module
.build;
println!;
Serialization
use Snapshot;
let snapshot = default;
// To JSON
let json = to_string?;
// From JSON
let parsed: Snapshot = from_str?;
Features
| Feature | Description |
|---|---|
serde |
JSON/MessagePack serialization via serde |
minicbor |
Compact CBOR binary format |
std |
Standard library support (enabled by default) |
no_std Support
This crate supports no_std environments with alloc:
[]
= { = "0.1", = false, = ["serde"] }
JSON Schema
A formal JSON Schema is available at schema/snapshot.schema.json.
This enables:
- Validation of snapshots from any language
- Auto-generation of types for non-Rust systems
- Documentation of the wire format
Example Snapshot
Field Reference
| Field | Type | Required | Description |
|---|---|---|---|
version.major |
u32 | Yes | Breaking changes increment this |
version.minor |
u32 | Yes | Backwards-compatible additions |
timestamp_ms |
u64 | Yes | Unix timestamp in milliseconds |
modules |
object | Yes | Map of module name to metrics |
reads.*.count |
u64 | Yes | Total messages read |
reads.*.backlog |
u64 | No | Unread messages waiting |
reads.*.pending |
u64 | No | Wait time in microseconds |
reads.*.rate |
f64 | No | Messages per second |
writes.*.count |
u64 | Yes | Total messages written |
writes.*.pending |
u64 | No | Backpressure time in microseconds |
writes.*.rate |
f64 | No | Messages per second |
Version Compatibility
The SchemaVersion type enables forward compatibility:
use SchemaVersion;
let version = current;
assert!; // true for current major version
- Major version change: Breaking format change, old parsers may fail
- Minor version change: New optional fields added, old parsers still work