Make MessagePack [Key] the slot authority and pin generic resolvers
.cc is MessagePack-based, so the core no longer pretends to be serializer-independent. GameCult.Caching references MessagePack.Annotations 3.1.7 and reads KeyAttribute and IgnoreMemberAttribute by type instead of matching their names. The benchmark's own MessagePack.Annotations reference is dropped; it arrives through GameCult.Caching. A generic document's options come from its generic definition's assembly: Doc<X> uses Doc's declared resolvers, never X's. GenericDocumentUsesItsOwnAssemblyResolvers compiles GenericHolder<T> into an assembly whose resolver writes Pair as [B, A] and checks the payload uses it rather than Pair's own assembly resolver. Contracts: schema-compatibility states the slot rule and its rejections; store-composition states the generic resolver rule. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
7c4bc2bdc0
commit
30bf7fd267
6 changed files with 82 additions and 24 deletions
|
|
@ -26,6 +26,17 @@ The canonical fixtures currently exercised in C# are:
|
|||
See `GameCult.Caching.Tests/BackingStoreTests.cs` for the canonical fixture
|
||||
documents and the expected receipts.
|
||||
|
||||
## Slots
|
||||
|
||||
A member's slot is its MessagePack `[Key(n)]` integer. MessagePack's `[Key]` and
|
||||
`[IgnoreMember]` are the single slot authority, so `GameCult.Caching` depends on
|
||||
`MessagePack.Annotations`. The registry and the generator (diagnostic GCC001)
|
||||
refuse, with the same message: 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 persisted
|
||||
member without a public or internal setter.
|
||||
|
||||
## Which schema a record carries
|
||||
|
||||
A record is written under the schema of its runtime type. Writing a derived
|
||||
|
|
|
|||
|
|
@ -216,6 +216,9 @@ another runtime need not obey the `storedAt` rule.
|
|||
generated and reflective serializers resolve options from the document's
|
||||
assembly. There is no mutable static, no registration call, and no load-order
|
||||
rule.
|
||||
- A generic document's options come from the generic definition's assembly:
|
||||
`Doc<X>` uses the resolvers `Doc`'s assembly declares, never `X`'s. A formatter
|
||||
for `X` that `Doc<X>` needs is declared in `Doc`'s assembly.
|
||||
- An assembly that declares nothing, and the store envelope, use the base
|
||||
options.
|
||||
- Deserialization runs under untrusted-data security. `CultRecordRef<T>` is a
|
||||
|
|
|
|||
|
|
@ -1021,32 +1021,13 @@ namespace GameCult.Caching
|
|||
private static string HiddenMemberMessage(string documentTypeName, string first, string second) =>
|
||||
$"Cult document {documentTypeName} member {first} hides persisted member {second}; persisted member names must be unique.";
|
||||
|
||||
private static bool IsIgnored(MemberInfo member)
|
||||
{
|
||||
return member.GetCustomAttributes().Any(attribute =>
|
||||
{
|
||||
var name = attribute.GetType().FullName;
|
||||
return name == "MessagePack.IgnoreMemberAttribute";
|
||||
});
|
||||
}
|
||||
private static bool IsIgnored(MemberInfo member) =>
|
||||
member.GetCustomAttribute<global::MessagePack.IgnoreMemberAttribute>() != null;
|
||||
|
||||
private static object? GetKeyValue(MemberInfo member)
|
||||
{
|
||||
foreach (var attribute in member.GetCustomAttributes())
|
||||
{
|
||||
var name = attribute.GetType().FullName;
|
||||
if (name == "MessagePack.KeyAttribute")
|
||||
{
|
||||
if (attribute.GetType().GetProperty("IntKey")?.GetValue(attribute) is int intKey)
|
||||
{
|
||||
return intKey;
|
||||
}
|
||||
|
||||
return attribute.GetType().GetProperty("StringKey")?.GetValue(attribute) as string;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
var key = member.GetCustomAttribute<global::MessagePack.KeyAttribute>();
|
||||
return key?.IntKey is int slot ? slot : key?.StringKey;
|
||||
}
|
||||
|
||||
private static string Sha256(string input)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MessagePack.Annotations" Version="3.1.7" />
|
||||
<PackageReference Include="R3" Version="1.3.0" />
|
||||
<PackageReference Include="ConcurrentHashSet " Version="1.3.0" />
|
||||
<InternalsVisibleTo Include="GameCult.Caching.Tests" />
|
||||
|
|
|
|||
Loading…
Reference in a new issue