Send the owner its outstanding mutation offer over v10
Session protocol v10 adds type 26: the life's earned offer with its unranked candidates in operator order and each successor's capability value, maintenance and total mass. The cellular bridge sends it when the offer or the owner's session changes and clears a consumed offer; the client keeps the latest one for the maintainer's choice UI (ADR-0121, 11.4d server half). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,8 @@ constexpr std::size_t intention_bytes = (std::size_t{4} * 8) + 4;
|
||||
constexpr std::size_t cellular_intention_bytes = (std::size_t{4} * 8) + 4 + 1 + 3 + 8;
|
||||
constexpr std::size_t cellular_action_bytes = (std::size_t{4} * 8) + 4 + 1 + 3 + 8;
|
||||
constexpr std::size_t cellular_mutation_action_bytes = (std::size_t{7} * 8) + 2 + 6;
|
||||
constexpr std::size_t cellular_offer_prefix_bytes = (std::size_t{4} * 8) + 2 + 6;
|
||||
constexpr std::size_t cellular_offered_candidate_bytes = 2 + 1 + 1 + 4 + 8 + 8;
|
||||
constexpr std::size_t cellular_perception_prefix_bytes = 8 + 8 + 2;
|
||||
constexpr std::size_t cellular_diagnostics_bytes = 64;
|
||||
constexpr std::size_t cellular_perception_v9_prefix_bytes =
|
||||
@@ -37,6 +39,22 @@ constexpr std::size_t life_receipt_bytes = 17;
|
||||
constexpr std::size_t life_outcome_bytes = 25;
|
||||
constexpr std::size_t life_query_bytes = 8;
|
||||
|
||||
// Seven capabilities and four effects (biology genome/mutation enums, frozen on the wire).
|
||||
bool valid_offer(const CellularMutationOffer& offer) {
|
||||
if (offer.tick == 0 || offer.candidates.size() > max_cellular_offered_candidates)
|
||||
return false;
|
||||
if (offer.candidates.empty())
|
||||
return offer.event_index == 0 && offer.offer_tick == 0;
|
||||
std::uint16_t previous = 0;
|
||||
for (const auto& candidate : offer.candidates) {
|
||||
if (candidate.operator_id <= previous || candidate.capability > 6 || candidate.effect > 3)
|
||||
return false;
|
||||
previous = candidate.operator_id;
|
||||
}
|
||||
return offer.life_identity != 0 && offer.event_index != 0 && offer.offer_tick != 0 &&
|
||||
offer.offer_tick <= offer.tick;
|
||||
}
|
||||
|
||||
bool valid_diagnostics(const CellularLifeDiagnostics& diagnostics) {
|
||||
const auto movement = static_cast<std::uint8_t>(diagnostics.movement);
|
||||
const auto intake = static_cast<std::uint8_t>(diagnostics.intake);
|
||||
@@ -130,6 +148,7 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message) {
|
||||
: session_protocol_v8)
|
||||
: std::holds_alternative<CellularAction>(message) ? session_protocol_v7
|
||||
: std::holds_alternative<CellularMutationAction>(message) ? session_protocol_v10
|
||||
: std::holds_alternative<CellularMutationOffer>(message) ? session_protocol_v10
|
||||
: std::holds_alternative<CellularIntention>(message) ? session_protocol_v6
|
||||
: is_life ? session_protocol_v5
|
||||
: session_protocol_version;
|
||||
@@ -161,6 +180,9 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
return {};
|
||||
if (version != session_protocol_v10 && std::holds_alternative<CellularMutationAction>(message))
|
||||
return {};
|
||||
if (const auto* offer = std::get_if<CellularMutationOffer>(&message);
|
||||
offer && (version != session_protocol_v10 || !valid_offer(*offer)))
|
||||
return {};
|
||||
if (const auto* action = std::get_if<CellularAction>(&message);
|
||||
action && action->engulf &&
|
||||
(version != session_protocol_v10 || action->has_intake_target || action->intake_x_um ||
|
||||
@@ -262,6 +284,25 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
put(out, 0, 6);
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const CellularMutationOffer& m) const {
|
||||
auto out = header(SessionMessageType::cellular_mutation_offer,
|
||||
cellular_offer_prefix_bytes +
|
||||
m.candidates.size() * cellular_offered_candidate_bytes,
|
||||
version);
|
||||
for (const auto value : {m.tick, m.life_identity, m.event_index, m.offer_tick})
|
||||
put(out, value, 8);
|
||||
put(out, m.candidates.size(), 2);
|
||||
put(out, 0, 6);
|
||||
for (const auto& candidate : m.candidates) {
|
||||
put(out, candidate.operator_id, 2);
|
||||
out.push_back(candidate.capability);
|
||||
out.push_back(candidate.effect);
|
||||
put(out, candidate.parameter, 4);
|
||||
put(out, candidate.maintenance, 8);
|
||||
put(out, candidate.total_mass, 8);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const CellularPerception& m) const {
|
||||
auto out = header(SessionMessageType::cellular_perception,
|
||||
(version == session_protocol_v9 || version == session_protocol_v10
|
||||
@@ -557,6 +598,35 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
return m;
|
||||
}
|
||||
case static_cast<std::uint8_t>(SessionMessageType::cellular_mutation_offer): {
|
||||
if (wire_version != session_protocol_v10)
|
||||
return std::unexpected(SessionCodecError::unsupported_version);
|
||||
if (payload.size() < cellular_offer_prefix_bytes)
|
||||
return std::unexpected(SessionCodecError::wrong_length);
|
||||
const auto count = static_cast<std::size_t>(get(payload, 32, 2));
|
||||
if (count > max_cellular_offered_candidates ||
|
||||
payload.size() !=
|
||||
cellular_offer_prefix_bytes + count * cellular_offered_candidate_bytes)
|
||||
return std::unexpected(SessionCodecError::wrong_length);
|
||||
CellularMutationOffer m;
|
||||
m.tick = get(payload, 0, 8);
|
||||
m.life_identity = get(payload, 8, 8);
|
||||
m.event_index = get(payload, 16, 8);
|
||||
m.offer_tick = get(payload, 24, 8);
|
||||
if (std::ranges::any_of(payload.subspan(34, 6),
|
||||
[](std::uint8_t value) { return value != 0; }))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
for (std::size_t i = 0; i < count; ++i) {
|
||||
const auto at = cellular_offer_prefix_bytes + i * cellular_offered_candidate_bytes;
|
||||
m.candidates.push_back({static_cast<std::uint16_t>(get(payload, at, 2)),
|
||||
payload[at + 2], payload[at + 3],
|
||||
static_cast<std::uint32_t>(get(payload, at + 4, 4)),
|
||||
get(payload, at + 8, 8), get(payload, at + 16, 8)});
|
||||
}
|
||||
if (!valid_offer(m))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
return m;
|
||||
}
|
||||
case static_cast<std::uint8_t>(SessionMessageType::cellular_perception): {
|
||||
if (wire_version != session_protocol_v8 && wire_version != session_protocol_v9 &&
|
||||
wire_version != session_protocol_v10)
|
||||
|
||||
Reference in New Issue
Block a user