Persist get-only and readonly members the way MessagePack does

The reflective registry now decides persistence from the same two facts
MessagePack 3.1.7's DynamicObjectResolver uses: whether it can assign a keyed
member after construction, and which constructor it picks.

- Every keyed public member is discovered, get-only properties included.
  MessagePack writes them all; the registry used to leave a get-only property
  out of the catalog and schema id even when a constructor filled it.
- MessagePack picks the [SerializationConstructor] if marked, otherwise the
  longest visible constructor whose parameters take the keyed members by
  position (probed: a longer non-matching constructor falls back to a shorter
  one). A member it cannot assign is read back only when its slot is below
  that constructor's parameter count.
- A readonly field is assignable under AllowPrivate (probed: round-trips with
  only a parameterless constructor), and otherwise only through the picked
  constructor. Keyed readonly fields that constructor fills are accepted.
- A keyed member MessagePack writes but never reads back is refused with a
  message naming the constructor position: a get-only property, a readonly
  field without AllowPrivate, or a non-public setter without AllowPrivate,
  when the picked constructor does not fill it (probed: loaded as default).
- An unkeyed public get-only property is refused; MessagePack throws "all
  public members must mark KeyAttribute or IgnoreMemberAttribute". The unkeyed
  message now names both fixes.

Schema ids change for five GameCult.Eve.Surface documents, whose keyed members
are all get-only properties filled by a [SerializationConstructor]:
gamecult.eve.surface, gamecult.eve.asset_catalog,
gamecult.eve.command_invocation, gamecult.eve.command_receipt and
gamecult.eve.provider_advertisement (EveProviderAdvertisementDocument). Their
catalogs gain those members. No .cc store under F:\Projects holds records of
these schemas: the gamecult.eve.provider_advertisement catalog in Gjallar's
scratch smoke stores belongs to GjallarProviderAdvertisementRecord, which has
no get-only members, and every other hit is prose or a git tree listing.

Consumer registration scan (CultLib src/tests/tools/samples, Ymir.Core,
Gjallar, AquaSynth Core/Faust, Mimir): 148 types register; the two rejections
(CounterState string key, BenchItem without [MessagePackObject]) are rejected
on 9139bf3 too.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-14 00:21:21 +02:00
commit 5bd4e4ed6e
3 changed files with 195 additions and 45 deletions

View file

@ -34,23 +34,32 @@ A member's slot is its MessagePack `[Key(n)]` integer. MessagePack's `[Key]` and
the registry refuses a document type without `[MessagePackObject]` and a
non-public document type without `[MessagePackObject(AllowPrivate = true)]`.
A member's type name is the CLR full name; a nested type is written `Outer+Inner`.
The registry also refuses a persisted member without `[Key]`, a string
`[Key]`, two members sharing a slot (including `new`-hidden members), a hidden
persisted member, an override whose `[Key]` or `[IgnoreMember]` differs from its
base declaration's (MessagePack reads the base declaration), and a readonly
persisted field.
The registry also refuses a public member without `[Key]` or `[IgnoreMember]`
(get-only properties included; MessagePack throws on them), a string `[Key]`,
two members sharing a slot (including `new`-hidden members), a hidden persisted
member, and an override whose `[Key]` or `[IgnoreMember]` differs from its base
declaration's (MessagePack reads the base declaration).
Visibility follows MessagePack's rule: the registry accepts what MessagePack
round-trips and refuses what it would silently lose. The registry persists
public fields and properties only. Without `AllowPrivate`, a persisted property
needs a public setter, and a `[Key]` on a non-public member is refused because
MessagePack skips that member. With `AllowPrivate`, private, internal and
init-only setters are all writable. But MessagePack then also reads non-public
members, so every non-public instance field or property must be
`[IgnoreMember]`. A class also needs a constructor MessagePack can call. That
is a parameterless one (public unless `AllowPrivate`), or one whose parameters
take the members at `[Key(0)]`, `[Key(1)]`, ... in order. A primary constructor
usually has neither.
every keyed public field and property, get-only ones included, because
MessagePack writes them all. A `[Key]` on a non-public member without
`AllowPrivate` is refused because MessagePack skips that member. With
`AllowPrivate`, MessagePack also reads non-public members, so every non-public
instance field or property must be `[IgnoreMember]`.
A class needs a constructor MessagePack can call: the `[SerializationConstructor]`
if one is marked, otherwise the longest constructor (public unless
`AllowPrivate`) whose every parameter takes the keyed member at its position
(`[Key(0)]`, `[Key(1)]`, ...). A parameterless constructor always qualifies; a
primary constructor usually does not. MessagePack reads a member back through
its setter, or through that constructor when the member's slot is below the
constructor's parameter count. A setter counts when it is public, or any setter
(private, internal, init-only) under `AllowPrivate`; a readonly field counts as
writable under `AllowPrivate` only. A keyed member MessagePack cannot read back
either way is refused: a get-only property, a readonly field without
`AllowPrivate`, or a property whose setter is non-public without
`AllowPrivate`, when the constructor does not fill it.
## Which schema a record carries