Saving and migration¶
30 types in this area.
On this page
FileMapSaveAdapter · IMapSaveAdapter · IMapSaveMigration · MapExplorationLoadResult · MapExplorationSaveCodec · MapExplorationSerializationResult · MapSaveDocumentKind · MapSaveEnvelope · MapSaveFailureKind · MapSaveFolder · MapSaveFolderFailure · MapSaveFolderResolution · MapSaveInspection · MapSaveInspector · MapSaveMigrationStep · MapSaveOperationResult · MapSaveReadResult · MapSaveRecoverySource · MapSaveSerializationResult · MapSaveSerializer · MapSaveV1ToV2Migration · MapStudioExportDiagnosticCodes · MapStudioExportDocument · MapStudioExportFailureCategory · MapStudioExportFingerprintCheck · MapStudioExportFingerprintPolicy · MapStudioExportFingerprints · MapStudioExportReadResult · MapStudioExportReader · MemoryMapSaveAdapter
FileMapSaveAdapter¶
:material-star: Start here
Waybranch.Core · Runtime/Core/Persistence/FileMapSaveAdapter.cs
Rooted file persistence. Writes flush a temporary file and atomically replace the primary while retaining its prior bytes as backup. Reads validate primary, then temporary, then backup without repairing or otherwise mutating any candidate.
Constructors
public FileMapSaveAdapter(string rootDirectory)-
Validates and normalizes an absolute, non-root, non-reparse storage directory and uses the built-in save serializer. -
rootDirectory— Absolute path of the directory slot files live in, typically a folder under the platform's persistent data path. It does not have to exist yet; it is created on the first write. public FileMapSaveAdapter(string rootDirectory, MapSaveSerializer serializer)-
Validates and normalizes the storage root, then retains a caller-supplied serializer for every slot operation. -
rootDirectory— Absolute path of the directory slot files live in. It does not have to exist yet; it is created on the first write. -serializer— Serializer used for every read and write through this adapter.
Properties
public string RootDirectory-
The directory every slot file is resolved inside, normalised to an absolute path with any trailing separator removed. It is a boundary rather than a hint: a slot ID whose resolved path would land outside this directory, or in a subdirectory of it, is refused instead of followed.
Methods
public MapSaveOperationResult TryDelete(StableId slotId)-
Deletes a slot by committing a durable deletion marker and then removing the committed save, the temporary file, and the backup. The marker is written and flushed before anything is removed, so a crash part-way through cannot leave a stale temporary file or backup that
TryReadwould happily load as a resurrected save. While the marker is present the slot reads asMapSaveFailureKind.NotFound; the next successful write clears it. -slotId— Slot to delete; an empty ID is refused as an unsafe path. - Returns — Success even when the slot held no files, since the deletion marker still records the intent. Failure when one of the slot's paths is a reparse point or the wrong kind of entry, or when the marker or the cleanup throws. public MapSaveReadResult TryRead(StableId slotId)-
Attempts to read without throwing for expected invalid input; failure leaves output parameters at documented defaults. -
slotId— Slot to read; an empty ID is refused as an unsafe path. - Returns — The envelope and the file it was recovered from on success. On failure the kind is the most serious one seen across the candidates, and isMapSaveFailureKind.NotFoundboth when the slot has no files at all and when it carries a deletion marker. public MapSaveOperationResult TryWrite(StableId slotId, MapSaveEnvelope envelope)-
Serialises a save and publishes it to the slot, keeping the bytes it replaced as a backup. The new save is written to a private staging file, flushed all the way to the device, promoted to the slot's temporary file, and only then swapped over the committed save. A crash at any point therefore leaves either the previous save or a complete temporary file that
TryReadcan recover from; a half-written save is never left where a read would find it. Writing to a slot that was deleted revives it and clears its deletion marker. -slotId— Slot to publish to; an empty ID is refused as an unsafe path. -envelope— The current-format snapshot to validate and encode before any filesystem entry is changed. - Returns — Failure when the envelope will not serialise, when one of the slot's paths is a reparse point or the wrong kind of entry, or when the commit throws. In that last case any temporary file already published is deliberately left in place, because it is a valid recovery candidate.
IMapSaveAdapter¶
:material-star: Start here · :material-puzzle: Extension point — implement this yourself to change behaviour
Waybranch.Core · Runtime/Core/Persistence/MapSaveContracts.cs
The storage boundary for map saves: read, write, and delete one slot of complete save data. Waybranch never calls it for you -- your code picks the slot and the moment -- so where a save lives, whether that is memory, a rooted file, or a platform service, is an adapter decision rather than an engine one.
An implementation must report problems through the returned result instead of throwing,
must reject an empty slot ID as MapSaveFailureKind.UnsafePath, and must
persist serialized bytes from MapSaveSerializer rather than keeping live
MapGraph or MapProgressionState references -- a save that
aliases live objects is not a save. Decoding through that same serializer is what
migrates older formats and validates every field before a caller sees the envelope.
Methods
public MapSaveOperationResult TryDelete(StableId slotId)-
Attempts to delete without throwing for expected invalid input; failure leaves output parameters at documented defaults. -
slotId— The non-empty logical slot to clear; empty must fail without touching storage. - Returns — Success, or the typed reason the slot may still hold data. public MapSaveReadResult TryRead(StableId slotId)-
Attempts to read without throwing for expected invalid input; failure leaves output parameters at documented defaults. -
slotId— The non-empty logical slot to load; an empty id must returnMapSaveFailureKind.UnsafePath. - Returns — On success, the loaded envelope and the candidate that supplied it; on failure, a typed kind and the diagnostics behind it. public MapSaveOperationResult TryWrite(StableId slotId, MapSaveEnvelope envelope)-
Writes one slot, replacing whatever it held. The envelope must be valid at the current save format; an invalid one is rejected before any storage is touched. -
slotId— The non-empty logical slot whose serialized bytes should be replaced. -envelope— The current-format immutable snapshot to validate and serialize without retaining live graph references. - Returns — Success, or the typed reason the save did not commit.
IMapSaveMigration¶
:material-puzzle: Extension point — implement this yourself to change behaviour
Waybranch.Core · Runtime/Core/Persistence/MapSaveContracts.cs
One step of the save upgrade chain: it accepts an envelope at its declared source version
and returns the same run at its target version.
MapSaveSerializer applies the steps in order while loading an older save,
which is how a format change ships without invalidating live campaigns.
An implementation must be deterministic and free of Unity, editor, and global state; must
declare a target exactly one above its source; must return a new envelope instead of
mutating the one it was handed; and must leave the generator version, seed, rules
fingerprint, stored graph fingerprint, and canonical graph bytes untouched. The serializer
re-checks all of that after the call, so a step that throws, drifts, or returns the wrong
version fails the load as MapSaveFailureKind.MigrationFailed instead of
quietly rewriting a player's save.
Properties
public int SourceVersion-
The stored format version this step accepts. Must be at least 1, and no two steps in the chain may declare the same source.
public int TargetVersion-
The format version this step produces. Must be
SourceVersionplus one; an out-of-step target invalidates the whole configured chain.
Methods
public MapSaveEnvelope Migrate(MapSaveEnvelope previous)-
Raises one envelope by exactly one save format version. -
previous— The immutable source-version envelope to read without mutation while constructing its successor. - Returns — A new envelope reportingTargetVersionand carrying the same graph and manifest fields asprevious.
MapExplorationLoadResult¶
:material-star: Start here
Waybranch.Core · Runtime/Core/Persistence/MapExplorationSaveCodec.cs
Result of exploration deserialization.
Properties
public string Error-
Failure diagnostic.
public MapExplorationSession Session-
Restored session, or null on failure.
public bool Succeeded-
Whether a session was restored.
MapExplorationSaveCodec¶
:material-star: Start here
Waybranch.Core · Runtime/Core/Persistence/MapExplorationSaveCodec.cs
Separate, strict persistence codec for exploration sessions. Legacy save bytes are embedded as text.
Fields
public const int FormatVersion-
Version of the exploration envelope, independent from legacy save versions.
public const int MaximumJsonLength-
Maximum accepted and emitted JSON length.
Methods
public MapExplorationLoadResult TryDeserialize(string json, MapGraph expectedGraph = null)-
Parses and validates bounded JSON, then restores immutable history only when graph identity and encoded policy data are compatible. -
json— Exploration JSON. -expectedGraph— Optional graph identity required by the caller. - Returns — A restored session or a typed failure result. public MapExplorationSerializationResult TrySerialize(MapExplorationSession session)-
Builds a bounded, canonical JSON envelope containing graph identity, progression counters, history, payloads, and revisit policy. -
session— Session to serialize. - Returns — A strict JSON result; invalid sessions are returned as failures.
MapExplorationSerializationResult¶
:material-star: Start here
Waybranch.Core · Runtime/Core/Persistence/MapExplorationSaveCodec.cs
Result of exploration serialization.
Properties
public string Error-
Failure diagnostic.
public string Json-
Exploration envelope JSON, empty on failure.
public bool Succeeded-
Whether JSON was produced.
MapSaveDocumentKind¶
Waybranch.Core · Runtime/Core/Persistence/MapSaveInspector.cs
Which kind of save text MapSaveInspector found.
| Value | Meaning |
|---|---|
Unknown |
The text could not be read far enough to tell. |
MapSave |
A map save of MapSaveSerializer (formats 1 and 2). |
ExplorationSave |
An exploration save of MapExplorationSaveCodec, which embeds a map save as text. |
MapSaveEnvelope¶
:material-star: Start here
Waybranch.Core · Runtime/Core/Persistence/MapSaveEnvelope.cs
A complete, versioned graph and traversal snapshot.
Constructors
public MapSaveEnvelope( int formatVersion, int generatorVersion, uint seed, string rulesFingerprint, string graphFingerprint, MapGraph graph, MapProgressionState progression, MapDataPayload customerMetadata)-
Assembles an envelope from its parts, without checking that they agree. Prefer
CreateCurrentfor a save you are about to write, since it fills the version and manifest fields from the graph itself. This constructor exists for the two cases that must state a version rather than assume the current one: reading a save back, and migrating one forward. -formatVersion— The serialized envelope schema revision represented by these fields. -generatorVersion— The map algorithm revision repeated from the embedded graph. -seed— Explicit unsigned deterministic seed; equal inputs and seed produce equal canonical output. -rulesFingerprint— The embedded graph's canonical rules digest; null is stored as empty text. -graphFingerprint— The canonical digest expected for the embedded graph; null is stored as empty text. -graph— The immutable map snapshot to retain by reference; this constructor permits null for deserialization diagnostics. -progression— How far the run had got on that map. -customerMetadata— Your own data to carry alongside the run. Null is stored asMapDataPayload.Empty.
Properties
public MapDataPayload CustomerMetadata-
Your own data carried alongside the run; nothing in the package reads it. Never null. It must be canonical or the save is refused, and it counts against the same per-payload property limit as a node payload. Format 1 had no such field, so a save from that version reads back with
MapDataPayload.Emptyhere. public int FormatVersion-
Which save format this envelope follows, and therefore which fields the reader expects to find. An envelope read from an older save keeps the version it was written at until a migration raises it; only
CurrentFormatVersionis ever written back out. public int GeneratorVersion-
The generator version recorded with the map, repeated at the top of the save so a reader can tell which algorithm built it without walking into the graph. It must agree with the embedded graph, which is what catches an envelope assembled around the wrong map.
public MapGraph Graph-
The map the run took place on, stored in full rather than as a seed to rebuild from, so a save still opens onto the map it was made on after the rules have moved on.
public string GraphFingerprint-
The canonical fingerprint of
Graph. Never null. Reading a save recomputes this from the graph it just deserialized and refuses the save when the two differ, so a hand-edited or truncated map is reported rather than loaded into a run. public MapProgressionState Progression-
How far the run had got: where the traveller stands, what may be entered next, and the results already recorded. It is checked against
Graphwhen the save is read, so progression naming a node that map does not hold is reported rather than restored. public string RulesFingerprint-
The canonical fingerprint of the rules the map was generated from, repeated from the embedded graph and required to match it. Never null. Compare it against the fingerprint of your current rules to spot a save made before a rules change.
public uint Seed-
The seed the map was generated from, repeated from the embedded graph and required to match it.
Fields
public const int CurrentFormatVersion-
The only envelope schema this build writes; older supported data is migrated to this revision first.
public const int FormatVersion1-
The original save schema containing graph and progression data without customer metadata.
public const int FormatVersion2-
The save schema that adds canonical customer metadata and version-two graph fields.
Methods
public static MapSaveEnvelope CreateCurrent( MapGraph graph, MapProgressionState progression, MapDataPayload customerMetadata = null)-
Creates a version-two envelope by copying generation metadata from the graph and computing its current canonical fingerprint; graph and progression references remain shared. -
graph— The complete immutable graph to embed and fingerprint; null throwsArgumentNullException. -progression— How far the run has got. -customerMetadata— Your own data to carry with the run. Null is stored asMapDataPayload.Empty. - Returns — An envelope at the current format, ready to serialize.
MapSaveFailureKind¶
:material-star: Start here
Waybranch.Core · Runtime/Core/Persistence/MapSaveContracts.cs
Why a save read, write, or delete did not succeed. Persistence returns these kinds
instead of throwing, and the kind is what a caller branches on:
MapSaveFailureKind.NotFound is a legitimate "no save here yet", while the
corrupt, version, and migration kinds mean a save exists but must not be loaded, and each
deserves its own player-facing message and support data.
| Value | Meaning |
|---|---|
None |
No failure. |
InvalidEnvelope |
The envelope offered for writing is invalid, or would not serialize. |
CorruptData |
The stored bytes are not canonical JSON, or fail validation. |
UnsupportedVersion |
The save was written by a newer, unsupported save format. |
MigrationMissing |
No contiguous migration covers this older save's version. |
MigrationFailed |
A migration threw, broke protected fields, or is non-contiguous. |
UnsafePath |
The slot ID was empty or resolved outside the storage root. |
NotFound |
The slot holds no save, or holds a deletion marker. |
IoFailure |
The storage layer failed the operation; stored data may be intact. |
MapSaveFolder¶
Waybranch.Core · Runtime/Core/Persistence/MapSaveFolder.cs
The rule WaybranchMapHost applies to its Save Folder, as a pure function: the folder is relative, has
no "." or ".." segment, and resolves strictly below the persistent-data root (ordinal comparison, ignoring case
only where the platform separator is a backslash). It reads no file and creates no folder.
Fields
public const string DefaultFolder-
The folder used when none is given.
Methods
public static MapSaveFolderResolution Resolve(string persistentRoot, string folder)-
Resolves a save folder below a persistent-data root. -
persistentRoot— The root, for example Unity'sApplication.persistentDataPath. -folder— The relative folder; null, empty or white space selectsDefaultFolder. - Returns — The resolved folder, or the reason it was refused; never null.
MapSaveFolderFailure¶
Waybranch.Core · Runtime/Core/Persistence/MapSaveFolder.cs
Why MapSaveFolder.Resolve refused a save folder.
| Value | Meaning |
|---|---|
None |
The folder was resolved. |
Rooted |
The folder is an absolute path; it must be relative to the persistent-data root. |
Empty |
The folder names no folder (only separators). |
Traversal |
The folder contains a "." or ".." segment. |
OutsideRoot |
The resolved folder is not below the persistent-data root. |
Invalid |
The path could not be normalized; MapSaveFolderResolution.ExceptionTypeName says why. |
MapSaveFolderResolution¶
Waybranch.Core · Runtime/Core/Persistence/MapSaveFolder.cs
The outcome of MapSaveFolder.Resolve.
Properties
public string ExceptionTypeName-
For
MapSaveFolderFailure.Invalid, the type name of the exception the path APIs threw. public MapSaveFolderFailure Failure-
Why the folder was refused, or
MapSaveFolderFailure.None. public string Folder-
The folder as it was checked: trimmed, or the default when none was given.
public string ResolvedRoot-
The absolute folder below the root, without a trailing separator; empty on failure.
public bool Succeeded-
Whether the folder resolved below the persistent-data root.
MapSaveInspection¶
Waybranch.Core · Runtime/Core/Persistence/MapSaveInspector.cs
What MapSaveInspector.Inspect(string) found in a save text. It names versions, migration steps,
fingerprints and the typed failure; it never carries text of the save.
Properties
public int CurrentFormatVersion-
The format version this build writes for this kind of save.
public int DeclaredFormatVersion-
The format version the text declares, or -1 when it could not be read.
public string DeclaredGraphFingerprint-
The graph fingerprint the save declares; empty when absent or unreadable.
public MapSaveInspection EmbeddedSave-
For an exploration save, the inspection of the map save it embeds; otherwise null.
public string FailureCategory-
A short category of the failure: one of syntax, size, depth, duplicate-key, string, number (the parser), schema, version, migration, fingerprint, manifest, progression, validation; empty when the load succeeds.
public string FailureCode-
The stable code a load reports first (a
bw.save.*code), or empty. public MapSaveFailureKind FailureKind-
The typed reason a load of this text fails, or
MapSaveFailureKind.None. public int FailureOffset-
Character offset of a parser failure, or -1.
public bool GraphFingerprintMatches-
Whether both fingerprints are present and equal.
public MapSaveDocumentKind Kind-
Map save, exploration save, or unknown.
public IReadOnlyList<MapSaveMigrationStep> MigrationSteps-
The steps of the built-in migration chain a load runs for the declared version, in order.
public string RecomputedGraphFingerprint-
The fingerprint recomputed from the stored graph; empty when the graph could not be read.
public bool Succeeded-
Whether a load of this text succeeds with the built-in migration chain.
MapSaveInspector¶
Waybranch.Core · Runtime/Core/Persistence/MapSaveInspector.cs
Inspects a save text in memory, without loading it into a run and without touching any file: the declared and
current format versions, the migration steps a load runs, the declared and recomputed graph fingerprints, and
the typed failure with its stable code. It uses the built-in migration chain only; custom migrations a game
registers on its own MapSaveSerializer are not seen. Pure and stateless.
Methods
public static MapSaveInspection Inspect(string json)-
Inspects a map save or an exploration save. -
json— The save text; null or empty is reported as corrupt data. - Returns — A new inspection; never null. public static MapSaveInspection Inspect(string json, CancellationToken cancellationToken)-
Inspects a map save or an exploration save with a cancellation token, for callers on a worker with a deadline. The token is checked between the parse, the read of the stored graph, the fingerprint and the load with migrations, and before the embedded save of an exploration save. -
json— The save text; null or empty is reported as corrupt data. -cancellationToken— Stops the inspection between steps; nothing is returned then. - Returns — A new inspection; never null.
MapSaveMigrationStep¶
Waybranch.Core · Runtime/Core/Persistence/MapSaveInspector.cs
One step of the built-in migration chain, from one stored format version to the next.
Constructors
public MapSaveMigrationStep(int from, int to)-
Describes one migration step; the inspector creates them for the built-in chain, one per version. -
from— Stored version the step reads. -to— Version the step produces.
Properties
public int From-
Stored version the step reads.
public int To-
Version the step produces.
MapSaveOperationResult¶
:material-star: Start here
Waybranch.Core · Runtime/Core/Persistence/MapSaveContracts.cs
The outcome of a save write or delete: whether it committed, the typed reason when it did not, and the diagnostics behind that reason. Only the persistence layer creates these, so a caller reads a result rather than building one.
Properties
public MapSaveFailureKind FailureKind-
MapSaveFailureKind.Noneexactly whenSucceededis true; a failed operation always names a kind. public bool Succeeded-
Whether the slot now holds what the call intended. False is not a promise that storage was left as it was found: only a refusal raised before storage is touched -- an unsafe slot ID, or an envelope that will not serialize -- leaves the slot alone. The shipped file adapter can also fail late, after publishing a temporary file, after committing the new save, or after writing a deletion marker, so re-read the slot rather than assuming the previous save is still the one
IMapSaveAdapter.TryReadwill return. public ValidationReport Validation-
Diagnostics for the operation. Never null; empty when nothing was reported.
MapSaveReadResult¶
:material-star: Start here
Waybranch.Core · Runtime/Core/Persistence/MapSaveContracts.cs
The outcome of a save read: the loaded envelope, which stored candidate supplied it, and
the diagnostics gathered on the way. A failed read carries no envelope, so check
MapSaveReadResult.Succeeded before touching
MapSaveReadResult.Envelope; a MapSaveFailureKind.NotFound read
is a slot with no save, not a broken one.
Properties
public MapSaveEnvelope Envelope-
The loaded save, or null when the read failed. An adapter that decodes through
MapSaveSerializerhands it back already migrated to the current save format and fully validated. public MapSaveFailureKind FailureKind-
MapSaveFailureKind.Noneexactly whenSucceededis true; a failed read always names a kind. public MapSaveRecoverySource RecoverySource-
Which candidate supplied the bytes, or
MapSaveRecoverySource.Noneon failure. Anything but Primary or Memory means the primary save was unusable and a fallback was accepted, which is usually worth surfacing to the player. public bool Succeeded-
Whether a save was loaded. Check it before
Envelope, which is null on failure; a true result may still carry warnings, since a recovery read succeeds while reporting the candidates it had to reject. public ValidationReport Validation-
Diagnostics for the read. Never null. A recovery read can succeed with warnings that name the rejected candidates, so do not discard it just because the read worked.
MapSaveRecoverySource¶
:material-star: Start here
Waybranch.Core · Runtime/Core/Persistence/MapSaveContracts.cs
Which stored candidate supplied the bytes of a successful read. Anything other than
MapSaveRecoverySource.Primary or MapSaveRecoverySource.Memory
means the primary save was missing or unusable and a validated fallback was accepted
instead; the read reports that as a warning and leaves every stored file as it found it.
| Value | Meaning |
|---|---|
None |
No candidate was accepted. |
Memory |
An in-process slot. |
Primary |
The slot's committed primary save. |
Temporary |
A published temporary file left behind by an interrupted write. |
Backup |
The bytes retained from the slot's previous successful write. |
MapSaveSerializationResult¶
:material-star: Start here
Waybranch.Core · Runtime/Core/Persistence/MapSaveContracts.cs
The outcome of one MapSaveSerializer call, in either direction. A serialize
fills MapSaveSerializationResult.Json and echoes the envelope it wrote; a
deserialize fills MapSaveSerializationResult.Envelope with the migrated,
validated save and leaves the JSON empty. A failure fills neither and names the kind
instead.
Properties
public MapSaveEnvelope Envelope-
The envelope that was serialized, or the one that was decoded and brought up to the current save format. Null when the call failed.
public MapSaveFailureKind FailureKind-
MapSaveFailureKind.Nonewhenever the call succeeded. public string Json-
The canonical JSON text produced by a successful serialize. Empty for deserialize results and for failures; never null.
public bool Succeeded-
Whether the call produced usable output. Which of
JsonandEnvelopeis filled depends on the direction the call ran in, so a true value alone does not tell you which to read. public ValidationReport Validation-
Diagnostics for the call. Never null; empty when nothing was reported.
MapSaveSerializer¶
:material-star: Start here
Waybranch.Core · Runtime/Core/Persistence/MapSaveSerializer.cs
Strict, culture-invariant JSON persistence for complete map save envelopes.
Constructors
public MapSaveSerializer()-
Configures the built-in one-step migration from save format 1 to the current format 2.
public MapSaveSerializer(IEnumerable<IMapSaveMigration> migrations)-
Indexes caller-provided one-version migration steps by source version. Null, duplicate, or non-consecutive steps mark the configuration invalid so loads fail with a typed migration error. -
migrations— The migration steps to enumerate once and retain by reference; the sequence itself is not retained.
Fields
public const int MaximumJsonLength-
The maximum accepted or emitted save text length: 16,777,216 UTF-16 code units.
public const int MaximumPayloadProperties-
The maximum property count allowed in each node, completion, or customer-metadata payload.
public const int MaximumSavedEdges-
The deserialization and envelope-validation ceiling for graph edges: 256 per supported node slot.
Methods
public MapSaveSerializationResult TryDeserialize(string json)-
Reads saved JSON back into an envelope at the current save format, running whatever migration steps stand between the stored version and this one. The parse is strict rather than forgiving: an object carrying an unknown field, or missing one, is corrupt data rather than something to read on a best-effort basis, and so is a value of the wrong JSON type or outside its numeric range. A save written by a newer build is reported as
MapSaveFailureKind.UnsupportedVersioninstead of being read partially. Each migration step is checked after it runs, not trusted: the seed, generator version, rules fingerprint, stored graph fingerprint, and canonical graph bytes must all come back unchanged, and the step must report exactly the version it declared. A step that throws or drifts fails the load asMapSaveFailureKind.MigrationFailed, which is what stops a faulty upgrade from quietly rewriting a player's run. The envelope is validated both as it was stored and again after the last step, so a caller never sees a half-migrated save. -json— Canonical save text no longer thanMaximumJsonLength; null or malformed text returns a corrupt-data result. - Returns — The migrated, validated envelope, or the typed reason it could not be loaded. The JSON field of the result is empty either way. public MapSaveSerializationResult TrySerialize(MapSaveEnvelope envelope)-
Writes one envelope to canonical JSON. The envelope is validated at the current save format first, so an invalid one is refused rather than written out and rejected on the way back in. Field order, number formatting, and string escaping are all fixed and culture-invariant, which is what makes the text comparable byte for byte between two runs, two machines, and two locales. Text longer than
MaximumJsonLengthis refused, as is anything that throws while being written, so this never propagates an exception from the writer. -envelope— The current-format graph and progression snapshot to validate and encode; it is not mutated or retained by the serializer. - Returns — The JSON text and the envelope it came from, or the typed reason nothing was produced.
MapSaveV1ToV2Migration¶
:material-star: Start here
Waybranch.Core · Runtime/Core/Persistence/MapSaveMigrations.cs
Save format 1 had no customer metadata field. Version 2 adds it without altering graph or progression objects, so their canonical bytes and graph fingerprint remain unchanged.
Properties
public int SourceVersion-
Save format 1, the original format, which this step accepts.
public int TargetVersion-
Save format 2, which this step produces.
Methods
public MapSaveEnvelope Migrate(MapSaveEnvelope previous)-
Rebuilds a version 1 envelope as a version 2 one, carrying every field across unchanged and giving the new customer metadata field its empty value, since a version 1 save had nowhere to store any. The result is a new envelope;
previousis not modified, and the graph and progression objects are shared with it rather than copied, which is what keeps the canonical graph bytes and the graph fingerprint identical across the step. -previous— The non-null format-one envelope whose graph and progression references are carried into the new wrapper unchanged. - Returns — The same run reported at version 2.
MapStudioExportDiagnosticCodes¶
Waybranch.Core · Runtime/Core/Persistence/MapStudioExportReader.cs
Stable codes of MapStudioExportReader, one per reason a Map Studio export is refused or flagged.
Match these codes ordinally; the messages are for people and may change.
Fields
public const string DepthExceeded-
Objects and arrays nest deeper than 64 levels.
public const string DuplicateKey-
An object repeats a key.
public const string FieldInvalid-
A field has the wrong JSON type or a value outside its range.
public const string FieldMissing-
A field the export format requires is missing.
public const string FieldUnknown-
An object has a field the export format does not define.
public const string FingerprintMismatch-
A declared fingerprint differs from the value recomputed from the export.
public const string JsonInvalid-
The text is empty or is not strict JSON (syntax).
public const string NotCanonical-
The export is valid but not in the canonical form Map Studio writes.
public const string NumberInvalid-
A number is not a 64-bit integer without fraction, exponent or leading zero.
public const string StableIdInvalid-
An ID is not a valid stable ID.
public const string StringInvalid-
A string has an unescaped control character, an unpaired surrogate or an invalid escape.
public const string TooLarge-
The text is longer than the size limit of the read.
public const string VersionUnsupported-
The export, rules, generator or graph version is not one this build reads.
MapStudioExportDocument¶
Waybranch.Core · Runtime/Core/Persistence/MapStudioExportReader.cs
The decoded content of a Map Studio export (format 1). Free text of the export (diagnostic messages and contexts, payload strings) is kept only where the domain types hold it (node payloads); the export's own diagnostics are reduced to severity and code.
Properties
public MapStudioExportFingerprints Declared-
The fingerprints as the export declares them.
public int ExportFormatVersion-
Always
MapStudioExportReader.ExportFormatVersion. public IReadOnlyList<string> ExportedCodes-
Code of each diagnostic the export carries, in export order. Text from the export: data, not instruction.
public IReadOnlyList<MapDiagnosticSeverity> ExportedSeverities-
Severity of each diagnostic the export carries, in export order.
public MapGenerationStatistics GenerationStatistics-
Search counters the export recorded for its last generation.
public int GeneratorVersion-
Generator version of the preview (1 or 2).
public MapGraph Graph-
The graph, or null when
GraphFormatVersionis 0. public int GraphFormatVersion-
Graph format version (1 or 2), or 0 when the preview had no graph.
public IReadOnlyList<StableId> LockedNodeIds-
Locked node IDs, sorted and unique.
public MapGenerationMode Mode-
Generation mode of the preview.
public MapGenerationOverrides Overrides-
Pinned nodes and edge overrides.
public int RulesSchemaVersion-
Rule schema version of the preview (1 or 2).
public MapGenerationSearchOptions SearchOptions-
The search budgets as authored; they may be above the defaults.
public uint Seed-
Seed of the preview.
MapStudioExportFailureCategory¶
Waybranch.Core · Runtime/Core/Persistence/MapStudioExportReader.cs
Why a read stopped before a document was built.
| Value | Meaning |
|---|---|
None |
The structure was read. |
JsonInvalid |
See MapStudioExportDiagnosticCodes.JsonInvalid. |
TooLarge |
See MapStudioExportDiagnosticCodes.TooLarge. |
DepthExceeded |
See MapStudioExportDiagnosticCodes.DepthExceeded. |
DuplicateKey |
See MapStudioExportDiagnosticCodes.DuplicateKey. |
StringInvalid |
See MapStudioExportDiagnosticCodes.StringInvalid. |
NumberInvalid |
See MapStudioExportDiagnosticCodes.NumberInvalid. |
FieldMissing |
See MapStudioExportDiagnosticCodes.FieldMissing. |
FieldUnknown |
See MapStudioExportDiagnosticCodes.FieldUnknown. |
FieldInvalid |
See MapStudioExportDiagnosticCodes.FieldInvalid. |
VersionUnsupported |
See MapStudioExportDiagnosticCodes.VersionUnsupported. |
StableIdInvalid |
See MapStudioExportDiagnosticCodes.StableIdInvalid. |
MapStudioExportFingerprintCheck¶
Waybranch.Core · Runtime/Core/Persistence/MapStudioExportReader.cs
The outcome of comparing one declared fingerprint with the recomputed value.
| Value | Meaning |
|---|---|
NotChecked |
Not compared: the value was not declared (and not required), or the reader cannot recompute it. |
Match |
The declared value equals the recomputed one. |
Mismatch |
The declared value differs, or is missing while the policy requires it. |
MapStudioExportFingerprintPolicy¶
Waybranch.Core · Runtime/Core/Persistence/MapStudioExportReader.cs
How MapStudioExportReader treats the canonical form and the declared fingerprints.
| Value | Meaning |
|---|---|
VerifyIfPresent |
Fingerprints that are declared (non-empty) are checked; a difference, or a text that is not canonical, is a warning and the read still succeeds. |
Require |
Every fingerprint must be declared and match, and the text must be canonical; otherwise the read fails. |
MapStudioExportFingerprints¶
Waybranch.Core · Runtime/Core/Persistence/MapStudioExportReader.cs
The five fingerprints of an export; an empty string means "not declared" or "not computed".
Constructors
public MapStudioExportFingerprints(string rules, string overrides, string generationKey, string graph, string content)-
Groups the five lowercase SHA-256 values of one export; a null argument is kept as an empty string, meaning absent. -
rules— Rules fingerprint. -overrides— Overrides fingerprint. -generationKey— Generation key of a version-two graph. -graph— Graph fingerprint. -content— SHA-256 of the canonical export body.
Properties
public string Content-
SHA-256 of the canonical export body (everything before the content fingerprint, closed with a brace).
public string GenerationKey-
Generation key of a version-two graph; empty for a version-one graph or no graph.
public string Graph-
Canonical fingerprint of the graph; empty when the export has no graph.
public string Overrides-
Fingerprint of the node and edge overrides.
public string Rules-
Fingerprint of the rules the preview used. The reader cannot recompute it without those rules.
MapStudioExportReadResult¶
Waybranch.Core · Runtime/Core/Persistence/MapStudioExportReader.cs
The result of MapStudioExportReader.TryRead(string, MapStudioExportFingerprintPolicy).
Properties
public MapStudioExportFingerprintCheck ContentCheck-
Comparison of the content fingerprint.
public MapStudioExportFingerprints Declared-
The fingerprints as declared.
public MapStudioExportDocument Document-
The decoded document; null when the structure could not be read.
public MapStudioExportFingerprints Expected-
The fingerprints recomputed from the document (rules stays empty: the export does not carry rules).
public MapStudioExportFailureCategory FailureCategory-
Why the structure could not be read;
MapStudioExportFailureCategory.Nonewhen it was. public string FailureCode-
The code of the structural failure, or empty.
public string FailureField-
The format field where the failure was found, written with schema names and indices only (for example "nodes[3].payload"); never text from the export. Empty when the failure is not tied to a field.
public int FailureOffset-
Character offset of the failure in the text, or -1 when it has none.
public MapStudioExportFingerprintCheck GenerationKeyCheck-
Comparison of the generation key.
public MapStudioExportFingerprintCheck GraphCheck-
Comparison of the graph fingerprint.
public bool IsCanonical-
Whether the text is byte for byte what Map Studio would write for the same document.
public MapStudioExportFingerprintCheck OverridesCheck-
Comparison of the overrides fingerprint.
public MapStudioExportFingerprintCheck RulesCheck-
Comparison of the rules fingerprint; always
MapStudioExportFingerprintCheck.NotCheckedhere. public bool Succeeded-
True when a document was built and, with
MapStudioExportFingerprintPolicy.Require, the text is canonical and every fingerprint matches. public ValidationReport Validation-
The reader's diagnostics: the structural failure, or the canonical-form and fingerprint findings (warnings with
MapStudioExportFingerprintPolicy.VerifyIfPresent, errors withMapStudioExportFingerprintPolicy.Require). Messages are fixed sentences and contexts name format fields; neither repeats text from the export.
MapStudioExportReader¶
Waybranch.Core · Runtime/Core/Persistence/MapStudioExportReader.cs
Strict reader of the JSON that Map Studio exports (format 1). It parses with the same rules as the save reader (16,777,216 UTF-16 code units, nesting depth 64, unique keys, 64-bit integers only), requires exactly the fields of the format, rebuilds the graph and the overrides, re-serializes them in canonical form and recomputes the fingerprints. A failure carries a stable code, a category, an offset and a field name, never text from the input. The reader allocates and returns; it keeps no state between calls.
Fields
public const int ExportFormatVersion-
The only export format version this build reads.
public const int MaximumJsonLength-
The largest text the reader accepts by default, in UTF-16 code units.
Methods
public static MapStudioExportReadResult TryRead(string json, MapStudioExportFingerprintPolicy policy)-
Reads an export with the default size limit. -
json— Export text; null or empty isMapStudioExportDiagnosticCodes.JsonInvalid. -policy— How the canonical form and the fingerprints are treated. - Returns — The document and the findings, or the typed reason the text was refused. public static MapStudioExportReadResult TryRead(string json, MapStudioExportFingerprintPolicy policy, int maximumLength)-
Reads an export with a smaller size limit, for callers that must bound their work. -
json— Export text; null or empty isMapStudioExportDiagnosticCodes.JsonInvalid. -policy— How the canonical form and the fingerprints are treated. -maximumLength— Largest accepted length in UTF-16 code units, from 2 toMaximumJsonLength. - Returns — The document and the findings, or the typed reason the text was refused. public static MapStudioExportReadResult TryRead(string json, MapStudioExportFingerprintPolicy policy, int maximumLength, CancellationToken cancellationToken)-
Reads an export with a smaller size limit and a cancellation token, for callers on a worker with a deadline. The token is checked after the parse, between the items of every list, before the canonical rewrite and before each fingerprint is recomputed. -
json— Export text; null or empty isMapStudioExportDiagnosticCodes.JsonInvalid. -policy— How the canonical form and the fingerprints are treated. -maximumLength— Largest accepted length in UTF-16 code units, from 2 toMaximumJsonLength. -cancellationToken— Stops the read between steps; nothing is returned then. - Returns — The document and the findings, or the typed reason the text was refused.
MemoryMapSaveAdapter¶
:material-star: Start here
Waybranch.Core · Runtime/Core/Persistence/MemoryMapSaveAdapter.cs
An in-memory adapter that stores canonical JSON rather than live object references.
Constructors
public MemoryMapSaveAdapter()-
Starts an empty, thread-safe memory store using a serializer with the built-in format-one migration.
public MemoryMapSaveAdapter(MapSaveSerializer serializer)-
Starts an empty, thread-safe memory store that encodes and decodes each slot through the supplied serializer. -
serializer— The serializer instance retained for all reads and writes; null throwsArgumentNullException.
Methods
public MapSaveOperationResult TryDelete(StableId slotId)-
Drops whatever the slot held. Clearing a slot that holds no save still succeeds, and nothing survives the call: this adapter keeps no backup and writes no deletion marker, so a later read of the same slot reports
MapSaveFailureKind.NotFound. -slotId— The non-empty logical save slot to clear; a missing valid slot is still successful. - Returns — Success, or the typed reason the slot may still hold data. public MapSaveReadResult TryRead(StableId slotId)-
Attempts to read without throwing for expected invalid input; failure leaves output parameters at documented defaults. -
slotId— The non-empty logical save slot; empty returnsMapSaveFailureKind.UnsafePathwithout reading. - Returns — The decoded and migrated envelope on success, or the typed reason the read failed. public MapSaveOperationResult TryWrite(StableId slotId, MapSaveEnvelope envelope)-
Attempts to write without throwing for expected invalid input; failure leaves output parameters at documented defaults. -
slotId— The non-empty logical save slot to replace atomically. -envelope— The current-format snapshot to validate and serialize; only its JSON text is retained. - Returns — Success, or the typed reason nothing was stored.