CultLib/src/GameCult.Caching.MessagePack
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Meta Vens a92381e589 Write an unset CultRecordRef as "" in every position
452f928 made nil the unset wire form, including dictionary keys: a
Dictionary<CultRecordRef<H>, float> holding the empty key encoded it as C0.
Python msgpack refuses nil map keys under strict_map_key, its default, so
cultcache-py cannot decode such a record. Nil cannot be the one canonical
form; "" can, and every runtime reads it.

The writer always writes "". The reader still takes nil as unset, because
452f928/b85a828 stores and Aetheria's Cut 9 import wrote nil; such a record
converts to "" on its next save and is byte-stable after that. The
store-composition contract names "" for value and key position, requires
readers to accept nil, and tells other runtimes to write "".

The tests pin payload bytes, so each claim is consequential: an unset ref
writes "", reloads through a fresh cache and resaves byte-identical; a
nil-written legacy payload reads as unset and resaves as ""; a ref-keyed
dictionary with an empty key writes "", reads back unset and resaves
byte-identical. The nil writer fails every byte assertion, a reader taking
nil as a set key fails the legacy pair, and a reader taking "" as a set key
fails the read-back assertions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 21:34:23 +02:00
..
CultCacheFormatterResolverAttribute.cs Own serialization options by the document's assembly 2026-09-13 21:12:53 +02:00
CultCacheMessagePack.cs Compare dictionary keys under their owning document's serializer 2026-09-14 14:38:24 +02:00
CultDocumentMessagePackSerialization.cs Delete the CultCache MessagePack source generator 2026-09-13 23:38:08 +02:00
CultMessagePackSecurity.cs Own serialization options by the document's assembly 2026-09-13 21:12:53 +02:00
CultRecordRefFormatter.cs Write an unset CultRecordRef as "" in every position 2026-09-14 21:34:23 +02:00
DirectoryMessagePackBackingStore.cs Re-read the manifest outside the unleased load's exception filter 2026-09-14 14:51:37 +02:00
GameCult.Caching.MessagePack.csproj Reload a directory store pull that a writer committed under 2026-09-14 14:16:41 +02:00
README.md Delete the CultCache MessagePack source generator 2026-09-13 23:38:08 +02:00

GameCult.Caching.MessagePack

GameCult.Caching.MessagePack provides the canonical CultCache persistence format for the attribute-first GameCult.Caching stack.

Included Types

  • SingleFileMessagePackBackingStore
  • CultDocumentMessagePackSerialization
  • CultDocumentResolver
  • CultRecordRefFormatter<T>

Cult document payloads serialize through MessagePackSerializer with the options of the document's assembly (CultDocumentMessagePackSerialization.OptionsFor), after the reflective CultDocumentRegistry has accepted the document shape. The store snapshot format is written by hand against MessagePackWriter/MessagePackReader.

What It Does

  • stores whole CultCache snapshots in MessagePack
  • serializes attributed document payloads as MessagePack [Key(n)] arrays
  • keeps explicit CultRecordRef<T> values compact on disk/wire
  • preserves the cache/store split where metadata lives outside the domain model

Example Model

using GameCult.Caching;
using MessagePack;

[CultDocument("gamecult.item_data", "gamecult.item_data.v1")]
public sealed class ItemData
{
    [Key(0)] [CultName] public string Name = string.Empty;
    [Key(1)] public int Value;
}

Typical Usage

using GameCult.Caching;
using GameCult.Caching.MessagePack;

var cache = new CultCache();
var store = new SingleFileMessagePackBackingStore("Data.msgpack");

cache.AddBackingStore(store);
await cache.PullAllBackingStoresAsync();

Notes

  • Payload bytes are MessagePack. Store metadata and schema catalogs are also persisted through hand-written MessagePack array layouts in this package.
  • The raw CultNet document lane should treat these payload bytes as already blessed, not decode and re-encode them for sport.