From 744f2f78b1d9411cebd9f1bc0138d6360674b5e7 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 15 Oct 2026 02:58:10 +0200 Subject: [PATCH] Contracts: the written-member rule, readable ids and the codec's family check Co-Authored-By: Claude Sonnet 5.5 --- .../Contracts/cultcache-persistence-format.md | 14 +++++++++++--- .../Contracts/cultcache-store-composition.md | 6 ++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/GameCult.Caching/Contracts/cultcache-persistence-format.md b/src/GameCult.Caching/Contracts/cultcache-persistence-format.md index 2c83b102..966b2a1f 100644 --- a/src/GameCult.Caching/Contracts/cultcache-persistence-format.md +++ b/src/GameCult.Caching/Contracts/cultcache-persistence-format.md @@ -437,9 +437,17 @@ elements retargets nothing. of keyed structs, since a struct is a value and never an element, but an object list inside a keyed struct is walked like any other. The walk follows declared member types: a member declared `object` is untyped on disk, and a subclass's extra members under a - non-union base-typed member are not written, so neither is walked. A non-public `[Key]` - member on the way to an object list is refused at registration, because MessagePack - writes it only under `AllowPrivate` and the element-id walk reads public members. For an + non-union base-typed member are not written, so neither is walked. The walk reads the + members MessagePack writes: an integer `[Key]`, no `[IgnoreMember]`, a public field or a + property whose getter is public. Any other `[Key]` member on the way to an object list + (non-public, or a property with a non-public getter) is refused at registration, because + MessagePack writes it only under `AllowPrivate` and the element-id walk reads public + members. An id member needs a public setter or `init`, so the id MessagePack writes is read + back; one with a non-public setter, or one MessagePack does not write, is refused. A + `[MessagePackObject]` type is read by key even when it is `IEnumerable`; MessagePack + writes a keyed type that is also a collection (`ICollection`, `IList`, `IDictionary`) + as a collection, so C# refuses such a type at the first encode or decode when it is on the + path to an object list. For an object list, C# refuses at registration a concrete element type that is not keyed and `[MessagePackFormatter]` on any type, collection type or member on the way to the list or on the id member, and refuses at the first encode or decode of the document a formatter diff --git a/src/GameCult.Caching/Contracts/cultcache-store-composition.md b/src/GameCult.Caching/Contracts/cultcache-store-composition.md index c8e2f17b..f2990a3a 100644 --- a/src/GameCult.Caching/Contracts/cultcache-store-composition.md +++ b/src/GameCult.Caching/Contracts/cultcache-store-composition.md @@ -303,6 +303,12 @@ exclusive open of the same lock file exclude each other is not established. type does not claim it (registration refuses a non-public `[Key]` member on the way to an object list, so the private-member formatter writes every id). A value list (`List`, a list of a non-keyed class) is not on the path, so a resolver may claim it. +- The codec also checks, for every type on that path, that `StandardResolver` writes it + the way the walk reads it. A type read by key must be written by the object or union + resolver; a collection must be written by a collection resolver (generic, immutable or + builtin). Otherwise the codec refuses the document on first encode or decode, naming the + type. It also refuses, typed, a type MessagePack cannot build a formatter for, and a + resolver that throws while asked about one. - Deserialization runs under untrusted-data security. `CultRecordRef` is a permitted dictionary key, compared by its key string.