Contracts: the written-member rule, readable ids and the codec's family check
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1956145ea2
commit
744f2f78b1
2 changed files with 17 additions and 3 deletions
|
|
@ -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<T>`; MessagePack
|
||||
writes a keyed type that is also a collection (`ICollection<T>`, `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
|
||||
|
|
|
|||
|
|
@ -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<float2>`, 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<T>` is a
|
||||
permitted dictionary key, compared by its key string.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue