26inline std::string
antJson(
const std::vector<std::uint8_t>& bytes) {
30 std::string s =
"{\"ok\":true";
31 auto num = [&](
const char* key,
double v) {
32 std::snprintf(buf,
sizeof buf,
",\"%s\":%.17g", key, v);
35 auto pairs = [&](
const char* key,
const auto& list,
auto second) {
40 for (
const auto& e : list) {
41 std::snprintf(buf,
sizeof buf,
"%s[%d,%.17g]", first ?
"" :
",",
42 static_cast<int>(e.node), second(e));
48 num(
"version", bytes[0]);
49 num(
"type",
static_cast<int>(m.
type));
50 num(
"direction",
static_cast<int>(m.
direction));
57 num(
"length",
static_cast<double>(bytes.size()));
65 std::snprintf(buf,
sizeof buf,
",\"kinematics\":[%.9g,%.9g,%.9g", k.
x, k.
y, k.
z);
67 std::snprintf(buf,
sizeof buf,
",%.9g,%.9g,%.9g]", k.
vx, k.
vy, k.
vz);
Built-in teaching scenarios: one per network family, shaped like the repo's presets but scaled down t...
std::string antJson(const std::vector< std::uint8_t > &bytes)
bytes decoded by core::codec::deserialize, as JSON.
bool deserialize(const std::uint8_t *bytes, std::size_t len, AntMessage &msg)
Decode bytes into msg.
One entry on an ant's visited-node stack: a node and the trip time the ant took to reach it from the ...
Complete, copyable description of an ant packet.
NodeAddress src
Originating node.
double timeStart
Generation time, for trip-time accounting.
bool hasKinematics
Hello only (ADR-0025): the sender's position and velocity, sent as an optional trailing section when ...
NodeAddress dst
Final destination.
std::uint32_t seqNum
Widened from the original u_int8_t so it does not wrap after 256 ants (which silently broke (src,...
int broadcastBudget
Remaining number of times this ant may be (re)broadcast.
VisitedPath history
Back-ant stack: path being reinforced.
double lifeAnt
Repair-ant lifetime budget (seconds).
VisitedPath visited
Forward stack: nodes seen on the way out.
std::vector< HelloDest > helloDests
Hello-ant adverts.
A (destination, pheromone) advert carried by a hello ant for building the virtual pheromone table.
A node's position (m) and velocity (m/s) in the adapter's Cartesian frame (ADR-0025).