#pragma once #include "evo/server/lifecycle/primitive_lives.hpp" namespace evo::server { // Creation-only trace. Publication binds this header to the committed predecessor. // Generation records authorization evidence; replay grants no authority. struct PrimitiveBatchHeader { std::uint64_t world{}, region{}, frame{}; std::array predecessor{}; std::array predecessor_digest{}; std::uint64_t begin_tick{}, end_tick{}; friend bool operator==(const PrimitiveBatchHeader&, const PrimitiveBatchHeader&) = default; }; struct PrimitiveBirth { LifeRequest request{}; std::uint64_t identity{}, generation{}; Tick born{}; friend bool operator==(const PrimitiveBirth&, const PrimitiveBirth&) = default; }; struct PrimitiveBatch { PrimitiveBatchHeader header{}; std::vector births; friend bool operator==(const PrimitiveBatch&, const PrimitiveBatch&) = default; }; inline constexpr std::uint32_t primitive_batch_format = 1; inline constexpr std::size_t primitive_batch_header_bytes = 112; inline constexpr std::size_t primitive_birth_bytes = 48; inline constexpr std::size_t max_primitive_batch_bytes = primitive_batch_header_bytes + primitive_birth_bytes * max_primitive_lives; enum class PrimitiveBatchError : std::uint8_t { format, version, scope, state }; // 1..64 ticks, <=256 births, ordered by (born, account, request), unique accounts // and identities. Empty batches advance the owner's checkpoint tick without // progressing biology. No implicit reserve consumption or timer advancement. [[nodiscard]] std::expected, PrimitiveBatchError> encode_primitive_batch(const PrimitiveBatch& batch); [[nodiscard]] std::expected decode_primitive_batch(std::span bytes); // Clones the base and applies every funded birth; all-or-nothing. Caller MUST // match predecessor/digest/begin tick to its trusted committed manifest, then // compare replayed payload bytes with the proposed checkpoint. Allocation uses // the same value in each of the four distinct world identity namespaces. [[nodiscard]] std::expected, PrimitiveBatchError> replay_primitive_batch(const PrimitiveLives& base, const PrimitiveBatch& batch); } // namespace evo::server