CultCache interop: C# and Rust write a union and nested bytes, the other reads them read-only
All checks were successful
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Successful in 29m46s
All checks were successful
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Successful in 29m46s
Extends the existing cross-runtime harness (cultcache-ts interop test, C# and Rust interop peers) with write-shapes/read-shapes: a union field with two arms and bin members. Rust reads through the read-only snapshot door; leftover staging files of both runtimes sit beside the store and must survive the read, and the store bytes must not change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a23ac7755a
commit
e3bce664e0
3 changed files with 215 additions and 2 deletions
|
|
@ -51,6 +51,12 @@ static async Task<int> ProgramMainAsync(string[] args)
|
|||
case "edit-in-place":
|
||||
await EditInPlaceAsync(file, RequireArg(options, "kind"));
|
||||
return 0;
|
||||
case "write-shapes":
|
||||
await WriteShapesAsync(file);
|
||||
return 0;
|
||||
case "read-shapes":
|
||||
await ReadShapesAsync(file);
|
||||
return 0;
|
||||
case "hold-lock":
|
||||
HoldLock(file, int.Parse(RequireArg(options, "ms"), CultureInfo.InvariantCulture));
|
||||
return 0;
|
||||
|
|
@ -96,6 +102,49 @@ static async Task WriteAsync(string file, string runtimeId)
|
|||
WriteJsonLine(note);
|
||||
}
|
||||
|
||||
// Records a reader of a Bifrost-shaped store must open: a union field (two arms) and nested bytes (a bin member, a bin list).
|
||||
static async Task WriteShapesAsync(string file)
|
||||
{
|
||||
var cache = BuildCache(file);
|
||||
await cache.PullAllBackingStoresAsync();
|
||||
foreach (var shape in InteropShapes())
|
||||
await cache.AddAsync(shape, new CultRecordHandle<CultCacheInteropShape>(new CultRecordKey(shape.DocumentId)));
|
||||
cache.FlushAllBackingStores();
|
||||
WriteShapesJsonLine(InteropShapes());
|
||||
}
|
||||
|
||||
static async Task ReadShapesAsync(string file)
|
||||
{
|
||||
var cache = BuildCache(file);
|
||||
await cache.PullAllBackingStoresAsync();
|
||||
WriteShapesJsonLine(cache.AllEntries.OfType<CultCacheInteropShape>());
|
||||
}
|
||||
|
||||
static CultCacheInteropShape[] InteropShapes() =>
|
||||
[
|
||||
new() { DocumentId = "shape:text", Arm = new InteropTextArm { Text = "union arm 0" }, Raw = Enumerable.Range(0, 256).Select(i => (byte)i).ToArray() },
|
||||
new()
|
||||
{
|
||||
DocumentId = "shape:pack",
|
||||
Arm = new InteropPackArm { Label = "union arm 1", Chunks = [new byte[] { 0xc0, 0xc1, 0x00 }, [], [0x92, 0x01, 0x02]] },
|
||||
Raw = [0xde, 0xad, 0xbe, 0xef]
|
||||
}
|
||||
];
|
||||
|
||||
// One line, ordered by document id, in the form the Rust peer prints.
|
||||
static void WriteShapesJsonLine(IEnumerable<CultCacheInteropShape> shapes) =>
|
||||
Console.Out.WriteLine(JsonSerializer.Serialize(shapes.OrderBy(shape => shape.DocumentId, StringComparer.Ordinal).Select(shape => new
|
||||
{
|
||||
documentId = shape.DocumentId,
|
||||
arm = shape.Arm switch
|
||||
{
|
||||
InteropTextArm text => (object)new { kind = "text", text = text.Text },
|
||||
InteropPackArm pack => new { kind = "pack", label = pack.Label, chunks = pack.Chunks.Select(Convert.ToHexString).ToArray() },
|
||||
_ => throw new InvalidOperationException("Unknown arm.")
|
||||
},
|
||||
raw = Convert.ToHexString(shape.Raw)
|
||||
})));
|
||||
|
||||
static async Task ReadAsync(string file)
|
||||
{
|
||||
var cache = BuildCache(file);
|
||||
|
|
@ -328,3 +377,28 @@ public sealed class CultCacheInteropMark
|
|||
[Key(0)] public string Label { get; set; } = string.Empty;
|
||||
[Key(1)] [CultElementId] public string Id { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
[CultDocument("cultcache.interop-shape", "cultcache.interop_shape.v1")]
|
||||
[MessagePackObject]
|
||||
public sealed class CultCacheInteropShape
|
||||
{
|
||||
[Key(0)] [CultName] public string DocumentId { get; set; } = string.Empty;
|
||||
[Key(1)] public InteropArm Arm { get; set; } = new InteropTextArm();
|
||||
[Key(2)] public byte[] Raw { get; set; } = Array.Empty<byte>();
|
||||
}
|
||||
|
||||
[Union(0, typeof(InteropTextArm)), Union(1, typeof(InteropPackArm))]
|
||||
public abstract class InteropArm { }
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class InteropTextArm : InteropArm
|
||||
{
|
||||
[Key(0)] public string Text { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class InteropPackArm : InteropArm
|
||||
{
|
||||
[Key(0)] public string Label { get; set; } = string.Empty;
|
||||
[Key(1)] public List<byte[]> Chunks { get; set; } = new();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue