CultNet: refuse a binding serializer that returns null instead of defaulting
Some checks failed
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Failing after 16m9s
Some checks failed
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Failing after 16m9s
ToRawRecord's 'binding?.PayloadSerializer(document) ?? default' let the default serializer silently override a bound owner whose serializer returned null. The binding path now refuses (InvalidOperationException, naming type and schema); CreateRawDocumentPutMessage shares the same check instead of putting a null payload on the wire. Non-null results are unchanged. Closes cultlib-gaps:finding:cut-bytes-after-cs.s3.null-serializer-silent-fallback Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
75188fdefa
commit
f4e3359eaf
2 changed files with 32 additions and 3 deletions
|
|
@ -253,7 +253,7 @@ namespace GameCult.Networking
|
|||
RecordKey = handle.Key.Value,
|
||||
StoredAt = storedAt,
|
||||
PayloadEncoding = "messagepack",
|
||||
Payload = binding.PayloadSerializer(document),
|
||||
Payload = SerializeWithBinding(binding, document),
|
||||
SourceRuntimeId = options?.SourceRuntimeId,
|
||||
SourceAgentId = options?.SourceAgentId,
|
||||
SourceRole = options?.SourceRole,
|
||||
|
|
@ -652,8 +652,9 @@ namespace GameCult.Networking
|
|||
RecordKey = key.Value,
|
||||
StoredAt = storedAt,
|
||||
PayloadEncoding = "messagepack",
|
||||
Payload = binding?.PayloadSerializer(document) ??
|
||||
CultDocumentMessagePackSerialization.SerializeUntyped(document, document.GetType(), _documents),
|
||||
Payload = binding == null
|
||||
? CultDocumentMessagePackSerialization.SerializeUntyped(document, document.GetType(), _documents)
|
||||
: SerializeWithBinding(binding, document),
|
||||
SourceRuntimeId = options?.SourceRuntimeId,
|
||||
SourceAgentId = options?.SourceAgentId,
|
||||
SourceRole = options?.SourceRole,
|
||||
|
|
@ -661,6 +662,13 @@ namespace GameCult.Networking
|
|||
};
|
||||
}
|
||||
|
||||
// A binding owns its payload bytes: a serializer that returns null is a broken owner, refused here rather than
|
||||
// handed to the default serializer or onto the wire as a null payload.
|
||||
private static byte[] SerializeWithBinding(CultNetDocumentBinding binding, object document) =>
|
||||
binding.PayloadSerializer(document)
|
||||
?? throw new InvalidOperationException(
|
||||
$"The payload serializer bound to {binding.DocumentType.FullName} (schema '{binding.SchemaId}') returned null; a binding must return the payload bytes.");
|
||||
|
||||
private CultNetEdge ToEdge(CultNetSelectionEvaluator.EdgeMatch edge, bool wantDocument)
|
||||
{
|
||||
// R-E: ToRawRecord and ToEdge emit the same id for the same row - the wire schema id a
|
||||
|
|
|
|||
Loading…
Reference in a new issue