Module de
Available on crate features
dial9 and serde-deserialize only.Expand description
serde [Deserializer] for raw trace events.
This module presents a RawEvent (the
callback type yielded by Decoder::for_each_event)
as a flat map compatible with serde’s internally-tagged-enum representation.
§Mapping
The deserializer presents each event as a map with these entries (in order):
"event"→ the schema name (the discriminant for#[serde(tag = "event")])."timestamp_ns"→ the absolute frame-header timestamp (only if the schema hashas_timestamp = true).- One entry per schema field, keyed by field name.
Pool resolution is automatic:
FieldValueRef::PooledStringresolves through the decoder’sStringPooland presents as a string.FieldValueRef::PooledStackFramesresolves through the decoder’sStackPooland presents as a sequence ofu64.FieldValueRef::Nonepresents as serdeNone, so optional fields work transparently.
§Example
use dial9_trace_format::decoder::Decoder;
use serde::Deserialize;
#[derive(Deserialize)]
#[serde(tag = "event")]
enum MyEvent {
#[serde(rename = "PollStart")]
PollStart {
timestamp_ns: u64,
worker_id: u64,
},
#[serde(other)]
Other,
}
let mut dec = Decoder::new(bytes).unwrap();
dec.for_each_event(|raw| {
match raw.deserialize::<MyEvent>() {
Ok(MyEvent::PollStart { timestamp_ns, worker_id }) => {
println!("poll {worker_id} at {timestamp_ns}");
}
Ok(MyEvent::Other) => {}
Err(e) => eprintln!("decode error: {e}"),
}
}).unwrap();Structs§
- Deser
Error - Error returned when deserializing a trace event into a typed value fails.
Functions§
- from_
raw_ event - Deserialize a
RawEventintoT.