CultCache: a single-file version is the hash of the record's exact stored bytes, and a copied record keeps them

A record read from a store file carries the bytes it was read from (CultPersistedRecord.RawBytes, dropped when any field is
assigned) and is written as those bytes, the way a schema catalog entry already is. A version is therefore the SHA-256 of the
slice the file holds, whatever legal encoding its writer chose, not of C#'s re-encoding, and a write that copies a record leaves
its bytes and so its version alone. The contract says exactly that, so the parity cuts port it literally.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-03 09:48:24 +02:00
commit 6001ebf932
3 changed files with 35 additions and 12 deletions

View file

@ -306,6 +306,12 @@ public static class CultDocumentMessagePackSerialization
private static void WritePersistedRecord(ref MessagePackWriter writer, CultPersistedRecord record)
{
if (record.RawBytes is { } raw)
{
writer.WriteRaw(new ReadOnlySpan<byte>(raw));
return;
}
writer.WriteArrayHeader(record.Variant == null ? PersistedRecordFieldCount : VariantRecordFieldCount);
writer.Write(record.Key);
writer.Write(record.SchemaId);
@ -389,6 +395,7 @@ public static class CultDocumentMessagePackSerialization
public static CultPersistedRecord ReadPersistedRecord(ref MessagePackReader reader)
{
var start = reader.Position;
var fieldCount = reader.ReadArrayHeader();
var record = new CultPersistedRecord();
@ -429,6 +436,7 @@ public static class CultDocumentMessagePackSerialization
}
}
record.RawBytes = reader.Sequence.Slice(start, reader.Position).ToArray();
return record;
}