载入中...
搜索中...
未找到
GameSaveSession.cpp
浏览该文件的文档.
16GameSaveSession::GameSaveSession(std::string contentVersion) : contentVersion_(std::move(contentVersion)) {}
22 Diagnostic::error(DiagnosticCode::InvalidArgument, "game-save participant key is empty", "saveKey"));
33 Diagnostic::error(DiagnosticCode::InvalidArgument, "invalid game-save content migration", "fromVersion"));
36 Diagnostic::error(DiagnosticCode::Conflict, "duplicate game-save content migration", "fromVersion"));
40Result<std::string> GameSaveSession::snapshotJson(const SnapshotHashProvider& hashProvider) const {
50 Value::Object payload{{"contentVersion", Value(contentVersion_)}, {"participants", Value(std::move(states))}};
51 auto envelope = makeSnapshotEnvelope("game.save-session", gameSaveSchema(), SchemaVersion(1), PersistentId::nil(),
57Result<void> GameSaveSession::restoreJson(std::string_view json, const SnapshotHashProvider& hashProvider) {
69 Diagnostic::error(DiagnosticCode::UnknownVersion, "unknown game-save schema version", "schemaVersion"));
73 Diagnostic::error(DiagnosticCode::ParseError, "game-save payload requires exactly two fields", "payload"));
Single-transaction composition of domain save participants.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
Result< void > addContentMigration(std::string fromVersion, std::function< Result< Value >(const Value &)> migrate)
Register a direct old-to-current content migration before loading.
Definition GameSaveSession.cpp:29
Result< void > add(IGameSaveParticipant &participant)
Borrow one domain participant for this session's lifetime.
Definition GameSaveSession.cpp:18
GameSaveSession(std::string contentVersion)
Configure the exact current content contract; empty identifiers are rejected by operations.
Definition GameSaveSession.cpp:16
Result< std::string > snapshotJson(const SnapshotHashProvider &hashProvider) const
Capture and integrity-seal every participant in deterministic key order.
Definition GameSaveSession.cpp:40
Result< void > restoreJson(std::string_view json, const SnapshotHashProvider &hashProvider)
Verify, migrate and prepare all participants before any publication.
Definition GameSaveSession.cpp:57
One authoritative domain participating in a game save. @lifetime The participant and its live domain ...
Definition GameSaveSession.h:32
virtual std::string_view saveKey() const noexcept=0
Stable unique participant key within the game-save schema.
static std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Definition Identity.cpp:37
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
const std::string & asString() const
Return the string payload; the caller must have checked the kind.
Definition Value.cpp:207
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:209
Value * find(const std::string &key) noexcept
Return an object member, or nullptr when absent.
Definition Value.cpp:244
@ InvalidArgument
@ UnknownVersion
@ PreconditionViolation
@ Unsupported
@ ParseError
@ Conflict
@ Applied
Result< SnapshotEnvelope > parseSnapshotEnvelope(std::string_view json, const SnapshotHashProvider &hashProvider)
Parse and verify an envelope from canonical or compatible JSON text.
Definition Snapshot.cpp:190
detail::StrongUint64< detail::SchemaVersionTag > SchemaVersion
Persistent data-format version; not a runtime replacement generation.
Definition SchemaVersion.h:13
Result< std::string > serializeSnapshotEnvelope(const SnapshotEnvelope &snapshot)
Serialize an envelope as deterministic compact JSON.
Definition Snapshot.cpp:184
detail::StrongUint64< detail::SimulationTickTag > SimulationTick
Deterministic simulation time step; it is not wall-clock time.
Definition Time.h:31
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
detail::StrongUint64< detail::RevisionTag > Revision
Monotonic content/state revision used for optimistic-concurrency checks.
Definition Revision.h:13
std::function< Result< ContentId >(std::string_view canonicalInput)> SnapshotHashProvider
Injected content-digest implementation used by snapshots.
Definition Snapshot.h:36
Definition Container.h:602