载入中...
搜索中...
未找到
RuntimeSnapshot.h
浏览该文件的文档.
36inline eve::Result<std::uint64_t> runtimeSnapshotUint(const eve::Value& value, std::string_view path) {
42 eve::Diagnostic::error(eve::DiagnosticCode::ParseError, "runtime snapshot integer must be a decimal string",
51 eve::Diagnostic::error(eve::DiagnosticCode::ParseError, "runtime snapshot integer is out of range",
60 static const std::set<std::string> fields = {"active", "definition", "definitionGeneration", "instanceId", "state"};
66 eve::DiagnosticCode::ParseError, "runtime snapshot payload contains an unknown field", "state." + name,
97 const RuntimeInstance<State>& runtime, std::string type, eve::LogicalId schema, eve::SchemaVersion schemaVersion,
104 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "runtime snapshot encoder is required",
117 return eve::makeSnapshotEnvelope(std::move(type), std::move(schema), schemaVersion, runtime.identity().instanceId,
136 RuntimeInstance<State>& runtime, const eve::SnapshotEnvelope& snapshot, std::string_view expectedType,
149 "runtime snapshot schema version is not supported", "schemaVersion", {}, "common.definitions.snapshot"));
152 auto metadata = eve::validateSnapshotPayloadMetadata(snapshot.payload, snapshot.revision, snapshot.tick);
177 eve::Diagnostic::error(eve::DiagnosticCode::ParseError, "runtime snapshot instanceId is invalid",
181 auto generation = detail::runtimeSnapshotUint(object->at("definitionGeneration"), "payload.definitionGeneration");
183 const eve::definition::InstanceIdentity identity{*instanceId, std::move(definition).takeValue(),
186 if (snapshot.instanceId != identity.instanceId || identity.instanceId != runtime.identity().instanceId)
194 eve::DiagnosticCode::Conflict, "runtime snapshot definition reference does not match", "payload.definition",
199 eve::DiagnosticCode::StaleHandle, "runtime snapshot definition generation does not match the destination",
Common identity and hot-reload contract for typed runtime instances.
Versioned, integrity-checked persistence envelopes.
static Result< DefinitionRef > parse(std::string_view text)
Parse a namespace:name logical definition identifier.
Definition ResourceRef.cpp:44
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Human-readable, scoped identifier in the form namespace:name.
Definition Identity.h:411
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:180
Owns one strongly typed runtime state and its definition identity.
Definition DefinitionRuntime.h:292
static std::optional< Id128 > parse(std::string_view text) noexcept
Parses canonical UUID text.
Definition Identity.h:151
eve::Result< void > runtimeSnapshotShape(const eve::Value::Object &object)
Runtime snapshot shape.
Definition RuntimeSnapshot.h:59
eve::Result< std::uint64_t > runtimeSnapshotUint(const eve::Value &value, std::string_view path)
Runtime snapshot uint.
Definition RuntimeSnapshot.h:36
Definition DefinitionRuntime.cpp:6
eve::Result< eve::SnapshotEnvelope > snapshotRuntimeInstance(const RuntimeInstance< State > &runtime, std::string type, eve::LogicalId schema, eve::SchemaVersion schemaVersion, eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider &hashProvider, const RuntimeStateEncoder< State > &encode)
Capture a typed runtime instance in the common snapshot envelope.
Definition RuntimeSnapshot.h:96
eve::Result< void > restoreRuntimeInstance(RuntimeInstance< State > &runtime, const eve::SnapshotEnvelope &snapshot, std::string_view expectedType, const eve::LogicalId &expectedSchema, eve::SchemaVersion expectedVersion, const eve::SnapshotHashProvider &hashProvider, const RuntimeStateDecoder< State > &decode)
Verify and atomically restore a typed runtime instance.
Definition RuntimeSnapshot.h:135
std::function< eve::Result< State >(const eve::Value &)> RuntimeStateDecoder
Decodes one domain-owned runtime state from an owning Value.
Definition RuntimeSnapshot.h:31
std::function< eve::Result< eve::Value >(const State &)> RuntimeStateEncoder
Converts one domain-owned runtime state into an owning Value.
Definition RuntimeSnapshot.h:27
@ InvalidArgument
@ UnknownVersion
@ Unsupported
@ ParseError
@ StaleHandle
@ Conflict
detail::StrongUint64< detail::GenerationTag > Generation
Registry/object replacement generation used to reject stale handles.
Definition Generation.h:13
Result< void > validateSnapshotPayloadMetadata(const Value &payload, Revision revision, SimulationTick tick)
Validate optional payload copies of envelope revision and tick.
Definition Snapshot.cpp:80
Result< SnapshotEnvelope > makeSnapshotEnvelope(std::string type, LogicalId schema, SchemaVersion schemaVersion, PersistentId instanceId, Revision revision, SimulationTick tick, Value payload, const SnapshotHashProvider &hashProvider)
Construct and seal a snapshot envelope.
Definition Snapshot.cpp:103
Result< void > verifySnapshotEnvelope(const SnapshotEnvelope &snapshot, const SnapshotHashProvider &hashProvider)
Verify an envelope's content hash without modifying it.
Definition Snapshot.cpp:63
std::function< Result< ContentId >(std::string_view canonicalInput)> SnapshotHashProvider
Injected content-digest implementation used by snapshots.
Definition Snapshot.h:36
Stable outer format shared by persistence and cross-process snapshots.
Definition Snapshot.h:46
Canonical identity carried by every typed runtime instance.
Definition DefinitionRuntime.h:87