Skip to main content

Module encoding

Module encoding 

Source
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.

OffsetSizeField
04magic TCDN (54 43 44 4E)
42format version, u16, currently VERSION = 1
62reserved, u16, must be 0
84point count n, u32
124edge count e, u32
164wait count w, u32
2021 npoint records
20 + 21 n16 eedge records
20 + 21 n + 16 e16 wwait records
end - 44CRC-32/ISO-HDLC (crc32()) of every byte before it, u32

Records (point indices are u32, ticks i64):

  • point: tag u8 (0 executable, 1 contingent), activation u32, lo i64, hi i64; an executable point has all 20 bytes after the tag zero;
  • edge t_to - t_from <= weight: from u32, to u32, weight i64;
  • wait: waiter u32, contingent u32, delay i64.

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§

DecodeError
Reasons an encoding was rejected.
EncodeError
Reasons a network could not be encoded.

Constants§

MAGIC
First four bytes of every encoding.
VERSION
Format version written by encode_into and 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 out and returns the number of bytes written.
encoded_len
Length in bytes of the encoding of a network with the given counts, or None if a count exceeds u32::MAX or the length overflows usize.