载入中...
搜索中...
未找到
Snapshot.cpp
浏览该文件的文档.
29 Diagnostic::error(DiagnosticCode::ParseError, "snapshot integer is out of range", std::string(field)));
51 Diagnostic::error(DiagnosticCode::InvalidArgument, "snapshot schema must be a valid logical ID", "schema"));
63Result<void> verifySnapshotEnvelope(const SnapshotEnvelope& snapshot, const SnapshotHashProvider& hashProvider) {
68 Diagnostic::error(DiagnosticCode::Unsupported, "snapshot hash provider is required", "contentHash"));
76 Diagnostic::error(DiagnosticCode::HashMismatch, "snapshot content hash does not match", "contentHash"));
80Result<void> validateSnapshotPayloadMetadata(const Value& payload, Revision revision, SimulationTick tick) {
91 DiagnosticCode::Conflict, "snapshot payload " + std::string(field) + " disagrees with the envelope",
103Result<SnapshotEnvelope> makeSnapshotEnvelope(std::string type, LogicalId schema, SchemaVersion schemaVersion,
106 SnapshotEnvelope snapshot{std::move(type), std::move(schema), schemaVersion, instanceId, revision, tick,
112 Diagnostic::error(DiagnosticCode::Unsupported, "snapshot hash provider is required", "contentHash"));
136Result<SnapshotEnvelope> parseSnapshotEnvelopeValue(const Value& value, const SnapshotHashProvider& hashProvider) {
140 DiagnosticCode::ParseError, "snapshot envelope must be an object with the exact public fields", {}));
153 !schemaText->second.isString() || !instanceId->second.isString() || !contentHash->second.isString())
162 Diagnostic::error(DiagnosticCode::ParseError, "snapshot envelope has invalid identity fields", {}));
190Result<SnapshotEnvelope> parseSnapshotEnvelope(std::string_view json, const SnapshotHashProvider& hashProvider) {
196Result<void> SnapshotMigrationChain::add(LogicalId schema, SchemaVersion from, SchemaVersion to, Migration migration) {
208Result<SnapshotEnvelope> SnapshotMigrationChain::migrate(SnapshotEnvelope snapshot, SchemaVersion targetVersion,
216 if (snapshot.schemaVersion == targetVersion) return Result<SnapshotEnvelope>::success(std::move(snapshot));
235 return makeSnapshotEnvelope(snapshot.type, snapshot.schema, snapshot.schemaVersion, snapshot.instanceId,
Versioned, integrity-checked persistence envelopes.
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
const std::string & format() const noexcept
Returns the canonical namespace:name representation.
Definition Identity.h:436
static std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Definition Identity.cpp:36
bool isValid() const noexcept
Returns whether this value contains a valid namespace and name.
Definition Identity.h:433
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
std::function< Result< Value >(const Value &payload)> Migration
Definition Snapshot.h:147
Result< SnapshotEnvelope > migrate(SnapshotEnvelope snapshot, SchemaVersion targetVersion, const SnapshotHashProvider &hashProvider) const
Migrate and reseal an envelope to an exact target version.
Definition Snapshot.cpp:208
Result< void > add(LogicalId schema, SchemaVersion from, SchemaVersion to, Migration migration)
Register one schema-local migration edge.
Definition Snapshot.cpp:196
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:57
std::string format() const
Formats the ID in lower-case canonical UUID text.
Definition Identity.h:173
static std::optional< Id128 > parse(std::string_view text) noexcept
Parses canonical UUID text.
Definition Identity.h:151
constexpr std::uint64_t value() const noexcept
Returns the underlying value at an explicit protocol boundary.
Definition StrongUint64.h:26
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:26
@ HashMismatch
@ InvalidArgument
@ UnknownVersion
@ Unsupported
@ ParseError
@ Conflict
Result< Value > snapshotEnvelopeValue(const SnapshotEnvelope &snapshot)
Convert an envelope to its strict canonical value representation.
Definition Snapshot.cpp:121
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 > 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 > snapshotHashInput(const SnapshotEnvelope &snapshot)
Produce the canonical JSON input used for a snapshot content hash.
Definition Snapshot.cpp:57
Result< SnapshotEnvelope > parseSnapshotEnvelopeValue(const Value &value, const SnapshotHashProvider &hashProvider)
Parse and verify an envelope from an owning Value.
Definition Snapshot.cpp:136
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
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