Skip to main content

Crate moq_ext_json

Crate moq_ext_json 

Source
Expand description

A latest-value JSON track writer that stamps each update itself.

A moq_json::snapshot track on a timed track needs a timestamp on every update, and moq-net refuses a group that starts at or before the group before it. A scalar value, such as a u64, starts a group with every change, so two changes in the same millisecond fail when the caller stamps them from a clock. ValueWriter stamps each update from the moq clock and moves a stamp that does not pass the previous one a tick past it, so update(&value) succeeds however often it is called.

The writer changes nothing on the wire. Readers use moq_json::snapshot::Consumer and see the stamps in Timed::at.

§Examples

use moq_ext_json::ValueWriter;
use moq_net::{Timescale, track};

let broadcast = moq_net::broadcast::Info::new().produce();
let track = broadcast
    .create_track(
        "latency",
        track::Info::default().with_timescale(Timescale::MILLI),
    )
    .ok_or("the track exists")?;
let latency = ValueWriter::<u64>::new(track, Default::default());
// Both succeed, even within one millisecond.
latency.update(&150)?;
latency.update(&160)?;

Structs§

ValueError
An error from a value track: a moq_json::Error that ? can convert.
ValueWriter
Writes a latest-value JSON track, stamping each update with the time it is made.