Expand description
Compact, checksummed binary encoding of a dispatchable network.
The ground side encodes a network once (encode_into, or
DispatchableNetwork::encode with alloc); the
onboard side validates and loads it with
Dispatcher::load_encoded, which reads the records
directly from the received bytes, needs no alloc and never panics.
§Format, version 1
All integers are little-endian and fixed-width; there is no padding or alignment.
| Offset | Size | Field |
|---|---|---|
| 0 | 4 | magic TCDN (54 43 44 4E) |
| 4 | 2 | format version, u16, currently VERSION = 1 |
| 6 | 2 | reserved, u16, must be 0 |
| 8 | 4 | point count n, u32 |
| 12 | 4 | edge count e, u32 |
| 16 | 4 | wait count w, u32 |
| 20 | 21 n | point records |
20 + 21 n | 16 e | edge records |
20 + 21 n + 16 e | 16 w | wait records |
| end - 4 | 4 | CRC-32/ISO-HDLC (crc32()) of every byte before it, u32 |
Records (point indices are u32, ticks i64):
- point: tag
u8(0 executable, 1 contingent), activationu32,loi64,hii64; an executable point has all 20 bytes after the tag zero; - edge
t_to - t_from <= weight:fromu32,tou32,weighti64; - wait:
waiteru32,contingentu32,delayi64.
Fixed-width records give random access to record i, which the validator needs to
follow activation chains without copying the network. The total length is
24 + 21 n + 16 (e + w) bytes and must match the buffer exactly.
§Decoding
Checks, in order, each with its own DecodeError: at least a header and a checksum
(DecodeError::Truncated), magic, version, exact length from the counts, the CRC, the
reserved field and point tags (canonical form), then everything
Dispatcher::load checks (indices, contingent bounds,
activation chains, waits, capacities, index type). A decoder for a later version is
expected to reject version 1 encodings it cannot read explicitly, never by checksum
failure: the magic and version come first so that the checksum location may change.
§Examples
use temporal_control::dispatch::encoding::{self, encoded_len};
use temporal_control::{DispatchEdge, Dispatcher, PointKind, Ticks, TimePoint};
let points = [PointKind::Executable; 2];
let edges = [DispatchEdge { from: TimePoint(0), to: TimePoint(1), weight: Ticks(10) }];
let mut buf = [0u8; 128];
let len = encoding::encode_into(&points, &edges, &[], &mut buf).expect("fits");
assert_eq!(Some(len), encoded_len(2, 1, 0));
let mut d = Dispatcher::<2, 2>::EMPTY;
d.load_encoded(&buf[..len]).expect("valid");Enums§
- Decode
Error - Reasons an encoding was rejected.
- Encode
Error - Reasons a network could not be encoded.
Constants§
- MAGIC
- First four bytes of every encoding.
- VERSION
- Format version written by
encode_intoand accepted by the decoder.
Functions§
- crc32
- CRC-32/ISO-HDLC of
bytes, the checksum of zlib, PNG and Ethernet. - encode_
into - Encodes a network into
outand returns the number of bytes written. - encoded_
len - Length in bytes of the encoding of a network with the given counts, or
Noneif a count exceedsu32::MAXor the length overflowsusize.