载入中...
搜索中...
未找到
Snapshot.h
浏览该文件的文档.
1#pragma once
2
14#include "common/Export.h"
15#include "common/Identity.h"
16#include "common/Result.h"
17#include "common/Revision.h"
19#include "common/Time.h"
20#include "common/Value.h"
21
22#include <functional>
23#include <map>
24#include <string>
25#include <string_view>
26
27namespace eve {
28
36using SnapshotHashProvider = std::function<Result<ContentId>(std::string_view canonicalInput)>;
37
56
70 std::string type, LogicalId schema, SchemaVersion schemaVersion, PersistentId instanceId, Revision revision,
72
80
88 const SnapshotHashProvider& hashProvider);
89
104
111
119 const Value& value, const SnapshotHashProvider& hashProvider);
120
129
137 std::string_view json, const SnapshotHashProvider& hashProvider);
138
146public:
147 using Migration = std::function<Result<Value>(const Value& payload)>;
148
157 [[nodiscard]] Result<void> add(LogicalId schema, SchemaVersion from, SchemaVersion to, Migration migration);
158
167 [[nodiscard]] Result<SnapshotEnvelope> migrate(SnapshotEnvelope snapshot, SchemaVersion targetVersion,
168 const SnapshotHashProvider& hashProvider) const;
169
170private:
171 struct Key {
172 std::string schema;
173 std::uint64_t from = 0;
174
176 friend bool operator<(const Key& left, const Key& right) noexcept {
177 return left.schema < right.schema || (left.schema == right.schema && left.from < right.from);
178 }
179 };
180
181 struct Step {
182 SchemaVersion to;
183 Migration migration;
184 };
185
186 std::map<Key, Step> steps_;
187};
188
189} // namespace eve
double value
Value::Object payload
std::string from
#define EVENGINE_API_FOUNDATION_INLINE
仅供"只有内联成员"的类型使用的组宏:拥有者 dllexport,消费方不导入。
Definition Export.h:170
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
HexVec3 left
HexVec3 right
HexCoordinates to
Cell the unit walks towards on this segment.
Definition HexUnits.cpp:64
Strong identity values shared by persistence, content and logical-name APIs.
std::uint64_t revision
Move-only, checked operation results for the common layer.
Monotonic state revision for concurrency and change checks.
Persistent data-contract version identity.
SimulationTick tick
Common time values and an injectable deterministic simulation clock.
Owning, renderer-independent dynamic values.
Human-readable, scoped identifier in the form namespace:name.
Definition Identity.h:411
Move-only operation result carrying either a value or Status.
Definition Result.h:155
One directed payload migration step.
Definition Snapshot.h:145
std::function< Result< Value >(const Value &payload)> Migration
Definition Snapshot.h:147
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
Id128 public API.
Definition Identity.h:112
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
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
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
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
SchemaVersion schemaVersion
Definition Snapshot.h:49
std::string type
Definition Snapshot.h:47
ContentId contentHash
Definition Snapshot.h:53
PersistentId instanceId
Definition Snapshot.h:50
SimulationTick tick
Definition Snapshot.h:52