diff --git a/crates/bindings-csharp/BSATN.Codegen/Type.cs b/crates/bindings-csharp/BSATN.Codegen/Type.cs index 537c1c9f2dc..ba1c13fd23f 100644 --- a/crates/bindings-csharp/BSATN.Codegen/Type.cs +++ b/crates/bindings-csharp/BSATN.Codegen/Type.cs @@ -624,21 +624,38 @@ public Scope.Extensions ToExtensions() if (Kind is TypeKind.Sum) { + extensions.BaseTypes.Add("SpacetimeDB.BSATN.IStructuralWrite"); + extensions.ExtraAttrs.Add("abstract"); + + extensions.Contents.Append( + $$""" + private {{ShortNameIdentifier}}() { } + + """ + ); + extensions.Contents.Append( string.Join( "\n", - Members.Select(m => - // C# puts field names in the same namespace as records themselves, and will complain about clashes if they match. - // To avoid this, we append an underscore to the field name. - // In most cases the field name shouldn't matter anyway as you'll idiomatically use pattern matching to extract the value. - $$""" - public sealed record {{m.Identifier}}({{m.Type.Name}} {{m.Identifier}}_) : {{ShortNameIdentifier}} - { - public override string ToString() => - $"{{m.Name}}({ SpacetimeDB.BSATN.StringUtil.GenericToString({{m.Identifier}}_) })"; - } - - """ + Members.Select( + (m, i) => + // C# puts field names in the same namespace as records themselves, and will complain about clashes if they match. + // To avoid this, we append an underscore to the field name. + // In most cases the field name shouldn't matter anyway as you'll idiomatically use pattern matching to extract the value. + $$""" + public sealed record {{m.Identifier}}({{m.Type.Name}} {{m.Identifier}}_) : {{ShortNameIdentifier}} + { + public override void WriteFields(System.IO.BinaryWriter writer) + { + writer.Write((byte){{i}}); + BSATN.{{m.Identifier}}{{TypeUse.BsatnFieldSuffix}}.Write(writer, {{m.Identifier}}_); + } + + public override string ToString() => + $"{{m.Name}}({ SpacetimeDB.BSATN.StringUtil.GenericToString({{m.Identifier}}_) })"; + } + + """ ) ) ); @@ -655,18 +672,7 @@ public override string ToString() => }; """; - write = $$""" - switch (value) { - {{string.Join( - "\n", - bsatnDecls.Select((m, i) => $""" - case {m.Identifier}(var inner): - writer.Write((byte){i}); - {m.Identifier}{TypeUse.BsatnFieldSuffix}.Write(writer, inner); - break; - """))}} - } - """; + write = "value.WriteFields(writer);"; getHashCode = $$""" switch (this) { diff --git a/crates/bindings-csharp/BSATN.Runtime/Attrs.cs b/crates/bindings-csharp/BSATN.Runtime/Attrs.cs index 6dc073d9873..00959910a19 100644 --- a/crates/bindings-csharp/BSATN.Runtime/Attrs.cs +++ b/crates/bindings-csharp/BSATN.Runtime/Attrs.cs @@ -1,6 +1,8 @@ namespace SpacetimeDB; +using System.IO; using System.Runtime.CompilerServices; +using SpacetimeDB.BSATN; [AttributeUsage( AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Enum, @@ -11,5 +13,8 @@ public sealed class TypeAttribute : Attribute { } // This could be an interface, but using `record` forces C# to check that it can // only be applied on types that are records themselves. -public abstract record TaggedEnum - where Variants : struct, ITuple { } +public abstract record TaggedEnum : IStructuralWrite + where Variants : struct, ITuple +{ + public abstract void WriteFields(BinaryWriter writer); +} diff --git a/crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs b/crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs index e7519e22765..31d890b3051 100644 --- a/crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs +++ b/crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs @@ -6,7 +6,41 @@ namespace SpacetimeDB.BSATN; /// Implemented by product types marked with [SpacetimeDB.Type]. /// All rows in SpacetimeDB are product types, so this is also implemented by all row types. /// -public interface IStructuralReadWrite +public interface IStructuralWrite +{ + /// + /// Write the fields of this type to the writer. + /// Throws an exception if the underlying writer throws. + /// Throws if this value is malformed (i.e. has null values for fields that + /// are not explicitly marked nullable.) + /// + /// + void WriteFields(BinaryWriter writer); + + public static byte[] ToBytes(RW rw, T value) + where RW : IReadWrite + { + using var stream = new MemoryStream(); + using var writer = new BinaryWriter(stream); + rw.Write(writer, value); + return stream.ToArray(); + } + + public static byte[] ToBytes(T value) + where T : IStructuralWrite + { + using var stream = new MemoryStream(); + using var writer = new BinaryWriter(stream); + value.WriteFields(writer); + return stream.ToArray(); + } +} + +/// +/// Implemented by product types marked with [SpacetimeDB.Type] that can be read from BSATN. +/// All rows in SpacetimeDB are product types, so this is also implemented by all row types. +/// +public interface IStructuralReadWrite : IStructuralWrite { /// /// Initialize this value from the reader. @@ -18,15 +52,6 @@ public interface IStructuralReadWrite /// void ReadFields(BinaryReader reader); - /// - /// Write the fields of this type to the writer. - /// Throws an exception if the underlying writer throws. - /// Throws if this value is malformed (i.e. has null values for fields that - /// are not explicitly marked nullable.) - /// - /// - void WriteFields(BinaryWriter writer); - /// /// Get an IReadWrite implementation that can read values of this type. /// In Rust, this would return IReadWrite<Self>, but the C# type system @@ -67,23 +92,11 @@ static T Read(BinaryReader reader) return result; } - public static byte[] ToBytes(RW rw, T value) - where RW : IReadWrite - { - using var stream = new MemoryStream(); - using var writer = new BinaryWriter(stream); - rw.Write(writer, value); - return stream.ToArray(); - } + public static new byte[] ToBytes(RW rw, T value) + where RW : IReadWrite => IStructuralWrite.ToBytes(rw, value); - public static byte[] ToBytes(T value) - where T : IStructuralReadWrite - { - using var stream = new MemoryStream(); - using var writer = new BinaryWriter(stream); - value.WriteFields(writer); - return stream.ToArray(); - } + public static new byte[] ToBytes(T value) + where T : IStructuralReadWrite => IStructuralWrite.ToBytes(value); } /// diff --git a/crates/bindings-csharp/BSATN.Runtime/Builtins.cs b/crates/bindings-csharp/BSATN.Runtime/Builtins.cs index f8cb375f284..d9388b528c8 100644 --- a/crates/bindings-csharp/BSATN.Runtime/Builtins.cs +++ b/crates/bindings-csharp/BSATN.Runtime/Builtins.cs @@ -108,8 +108,10 @@ public static byte[] StringToByteArray(string hex) // See `spacetimedb-sats::AlgebraicType::is_valid_for_client_type_[use|generate]` for more information. // We don't use [Type] here; instead we manually implement the serialization stuff that would be generated by // [Type] so that we can override GetAlgebraicType to return types in a special, Ref-less form. -public readonly partial struct Unit +public readonly partial struct Unit : IStructuralWrite { + public void WriteFields(BinaryWriter writer) { } + public readonly struct BSATN : IReadWrite { public Unit Read(BinaryReader reader) => default; @@ -124,7 +126,8 @@ public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) => [StructLayout(LayoutKind.Sequential)] public readonly record struct ConnectionId - : IEquatable, + : IStructuralWrite, + IEquatable, IComparable, IComparable { @@ -192,14 +195,16 @@ public static ConnectionId Random() return id; } + public void WriteFields(BinaryWriter writer) => + new SpacetimeDB.BSATN.U128Stdb().Write(writer, value); + // --- auto-generated --- public readonly struct BSATN : IReadWrite { public ConnectionId Read(BinaryReader reader) => new(new SpacetimeDB.BSATN.U128Stdb().Read(reader)); - public void Write(BinaryWriter writer, ConnectionId value) => - new SpacetimeDB.BSATN.U128Stdb().Write(writer, value.value); + public void Write(BinaryWriter writer, ConnectionId value) => value.WriteFields(writer); // --- / auto-generated --- @@ -239,7 +244,11 @@ public int CompareTo(object? value) } [StructLayout(LayoutKind.Sequential)] -public readonly record struct Identity : IEquatable, IComparable, IComparable +public readonly record struct Identity + : IStructuralWrite, + IEquatable, + IComparable, + IComparable { private readonly U256 value; @@ -296,13 +305,15 @@ public static Identity FromHexString(string hex) return FromBigEndian(Util.StringToByteArray(hex)); } + public void WriteFields(BinaryWriter writer) => + new SpacetimeDB.BSATN.U256().Write(writer, value); + // --- auto-generated --- public readonly struct BSATN : IReadWrite { public Identity Read(BinaryReader reader) => new(new SpacetimeDB.BSATN.U256().Read(reader)); - public void Write(BinaryWriter writer, Identity value) => - new SpacetimeDB.BSATN.U256().Write(writer, value.value); + public void Write(BinaryWriter writer, Identity value) => value.WriteFields(writer); // --- / auto-generated --- @@ -549,7 +560,7 @@ public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) => } } -public partial record ScheduleAt : TaggedEnum<(TimeDuration Interval, Timestamp Time)> +public abstract partial record ScheduleAt : TaggedEnum<(TimeDuration Interval, Timestamp Time)> { public static implicit operator ScheduleAt(TimeDuration duration) => new Interval(duration); @@ -580,9 +591,23 @@ internal enum ScheduleAtVariant : byte Time, } - public sealed record Interval(TimeDuration Interval_) : ScheduleAt; + public sealed record Interval(TimeDuration Interval_) : ScheduleAt + { + public override void WriteFields(BinaryWriter writer) + { + BSATN.__enumTag.Write(writer, ScheduleAtVariant.Interval); + BSATN.Interval.Write(writer, Interval_); + } + } - public sealed record Time(Timestamp Time_) : ScheduleAt; + public sealed record Time(Timestamp Time_) : ScheduleAt + { + public override void WriteFields(BinaryWriter writer) + { + BSATN.__enumTag.Write(writer, ScheduleAtVariant.Time); + BSATN.Time.Write(writer, Time_); + } + } public readonly partial struct BSATN : IReadWrite { @@ -600,21 +625,7 @@ public ScheduleAt Read(BinaryReader reader) => ), }; - public void Write(BinaryWriter writer, ScheduleAt value) - { - switch (value) - { - case Interval(var inner): - __enumTag.Write(writer, ScheduleAtVariant.Interval); - Interval.Write(writer, inner); - break; - - case Time(var inner): - __enumTag.Write(writer, ScheduleAtVariant.Time); - Time.Write(writer, inner); - break; - } - } + public void Write(BinaryWriter writer, ScheduleAt value) => value.WriteFields(writer); // --- / auto-generated --- @@ -682,6 +693,11 @@ public T UnwrapOrElse(Func f) => private Result() { } + public override void WriteFields(BinaryWriter writer) => + throw new NotSupportedException( + "Result requires a typed BSATN serializer to write its generic variants." + ); + internal enum ResultVariant : byte { Ok, diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/client/snapshots/Type#CustomTaggedEnum.verified.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/client/snapshots/Type#CustomTaggedEnum.verified.cs index 0f6a93c3c41..2d602afced1 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/client/snapshots/Type#CustomTaggedEnum.verified.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/client/snapshots/Type#CustomTaggedEnum.verified.cs @@ -2,16 +2,32 @@ // #nullable enable -partial record CustomTaggedEnum : System.IEquatable +abstract partial record CustomTaggedEnum + : System.IEquatable, + SpacetimeDB.BSATN.IStructuralWrite { + private CustomTaggedEnum() { } + public sealed record IntVariant(int IntVariant_) : CustomTaggedEnum { + public override void WriteFields(System.IO.BinaryWriter writer) + { + writer.Write((byte)0); + BSATN.IntVariantRW.Write(writer, IntVariant_); + } + public override string ToString() => $"IntVariant({SpacetimeDB.BSATN.StringUtil.GenericToString(IntVariant_)})"; } public sealed record StringVariant(string StringVariant_) : CustomTaggedEnum { + public override void WriteFields(System.IO.BinaryWriter writer) + { + writer.Write((byte)1); + BSATN.StringVariantRW.Write(writer, StringVariant_); + } + public override string ToString() => $"StringVariant({SpacetimeDB.BSATN.StringUtil.GenericToString(StringVariant_)})"; } @@ -36,17 +52,7 @@ public CustomTaggedEnum Read(System.IO.BinaryReader reader) public void Write(System.IO.BinaryWriter writer, CustomTaggedEnum value) { - switch (value) - { - case IntVariant(var inner): - writer.Write((byte)0); - IntVariantRW.Write(writer, inner); - break; - case StringVariant(var inner): - writer.Write((byte)1); - StringVariantRW.Write(writer, inner); - break; - } + value.WriteFields(writer); } public SpacetimeDB.BSATN.AlgebraicType.Ref GetAlgebraicType( diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Module#TestTableTaggedEnum.verified.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Module#TestTableTaggedEnum.verified.cs index 7e321681b88..a06afd87ec9 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Module#TestTableTaggedEnum.verified.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Module#TestTableTaggedEnum.verified.cs @@ -2,16 +2,32 @@ // #nullable enable -partial record TestTableTaggedEnum : System.IEquatable +abstract partial record TestTableTaggedEnum + : System.IEquatable, + SpacetimeDB.BSATN.IStructuralWrite { + private TestTableTaggedEnum() { } + public sealed record X(int X_) : TestTableTaggedEnum { + public override void WriteFields(System.IO.BinaryWriter writer) + { + writer.Write((byte)0); + BSATN.XRW.Write(writer, X_); + } + public override string ToString() => $"X({SpacetimeDB.BSATN.StringUtil.GenericToString(X_)})"; } public sealed record Y(int Y_) : TestTableTaggedEnum { + public override void WriteFields(System.IO.BinaryWriter writer) + { + writer.Write((byte)1); + BSATN.YRW.Write(writer, Y_); + } + public override string ToString() => $"Y({SpacetimeDB.BSATN.StringUtil.GenericToString(Y_)})"; } @@ -36,17 +52,7 @@ public TestTableTaggedEnum Read(System.IO.BinaryReader reader) public void Write(System.IO.BinaryWriter writer, TestTableTaggedEnum value) { - switch (value) - { - case X(var inner): - writer.Write((byte)0); - XRW.Write(writer, inner); - break; - case Y(var inner): - writer.Write((byte)1); - YRW.Write(writer, inner); - break; - } + value.WriteFields(writer); } public SpacetimeDB.BSATN.AlgebraicType.Ref GetAlgebraicType( diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Type#TestTaggedEnumField.verified.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Type#TestTaggedEnumField.verified.cs index 9f0584e348e..a5b5331c79e 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Type#TestTaggedEnumField.verified.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Type#TestTaggedEnumField.verified.cs @@ -2,16 +2,32 @@ // #nullable enable -partial record TestTaggedEnumField : System.IEquatable +abstract partial record TestTaggedEnumField + : System.IEquatable, + SpacetimeDB.BSATN.IStructuralWrite { + private TestTaggedEnumField() { } + public sealed record X(int X_) : TestTaggedEnumField { + public override void WriteFields(System.IO.BinaryWriter writer) + { + writer.Write((byte)0); + BSATN.XRW.Write(writer, X_); + } + public override string ToString() => $"X({SpacetimeDB.BSATN.StringUtil.GenericToString(X_)})"; } public sealed record Y(int Y_) : TestTaggedEnumField { + public override void WriteFields(System.IO.BinaryWriter writer) + { + writer.Write((byte)1); + BSATN.YRW.Write(writer, Y_); + } + public override string ToString() => $"Y({SpacetimeDB.BSATN.StringUtil.GenericToString(Y_)})"; } @@ -36,17 +52,7 @@ public TestTaggedEnumField Read(System.IO.BinaryReader reader) public void Write(System.IO.BinaryWriter writer, TestTaggedEnumField value) { - switch (value) - { - case X(var inner): - writer.Write((byte)0); - XRW.Write(writer, inner); - break; - case Y(var inner): - writer.Write((byte)1); - YRW.Write(writer, inner); - break; - } + value.WriteFields(writer); } public SpacetimeDB.BSATN.AlgebraicType.Ref GetAlgebraicType( diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Type#TestTaggedEnumInlineTuple.verified.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Type#TestTaggedEnumInlineTuple.verified.cs index 761bdacb92e..cfc44ce5ec4 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Type#TestTaggedEnumInlineTuple.verified.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Type#TestTaggedEnumInlineTuple.verified.cs @@ -2,10 +2,20 @@ // #nullable enable -partial record TestTaggedEnumInlineTuple : System.IEquatable +abstract partial record TestTaggedEnumInlineTuple + : System.IEquatable, + SpacetimeDB.BSATN.IStructuralWrite { + private TestTaggedEnumInlineTuple() { } + public sealed record Item1(int Item1_) : TestTaggedEnumInlineTuple { + public override void WriteFields(System.IO.BinaryWriter writer) + { + writer.Write((byte)0); + BSATN.Item1RW.Write(writer, Item1_); + } + public override string ToString() => $"Item1({SpacetimeDB.BSATN.StringUtil.GenericToString(Item1_)})"; } @@ -28,13 +38,7 @@ public TestTaggedEnumInlineTuple Read(System.IO.BinaryReader reader) public void Write(System.IO.BinaryWriter writer, TestTaggedEnumInlineTuple value) { - switch (value) - { - case Item1(var inner): - writer.Write((byte)0); - Item1RW.Write(writer, inner); - break; - } + value.WriteFields(writer); } public SpacetimeDB.BSATN.AlgebraicType.Ref GetAlgebraicType( diff --git a/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Type#CustomTaggedEnum.verified.cs b/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Type#CustomTaggedEnum.verified.cs index 78c43d2fb53..ea871a39085 100644 --- a/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Type#CustomTaggedEnum.verified.cs +++ b/crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Type#CustomTaggedEnum.verified.cs @@ -2,28 +2,56 @@ // #nullable enable -partial record CustomTaggedEnum : System.IEquatable +abstract partial record CustomTaggedEnum + : System.IEquatable, + SpacetimeDB.BSATN.IStructuralWrite { + private CustomTaggedEnum() { } + public sealed record IntVariant(int IntVariant_) : CustomTaggedEnum { + public override void WriteFields(System.IO.BinaryWriter writer) + { + writer.Write((byte)0); + BSATN.IntVariantRW.Write(writer, IntVariant_); + } + public override string ToString() => $"IntVariant({SpacetimeDB.BSATN.StringUtil.GenericToString(IntVariant_)})"; } public sealed record StringVariant(string StringVariant_) : CustomTaggedEnum { + public override void WriteFields(System.IO.BinaryWriter writer) + { + writer.Write((byte)1); + BSATN.StringVariantRW.Write(writer, StringVariant_); + } + public override string ToString() => $"StringVariant({SpacetimeDB.BSATN.StringUtil.GenericToString(StringVariant_)})"; } public sealed record NullableIntVariant(int? NullableIntVariant_) : CustomTaggedEnum { + public override void WriteFields(System.IO.BinaryWriter writer) + { + writer.Write((byte)2); + BSATN.NullableIntVariantRW.Write(writer, NullableIntVariant_); + } + public override string ToString() => $"NullableIntVariant({SpacetimeDB.BSATN.StringUtil.GenericToString(NullableIntVariant_)})"; } public sealed record NullableStringVariant(string? NullableStringVariant_) : CustomTaggedEnum { + public override void WriteFields(System.IO.BinaryWriter writer) + { + writer.Write((byte)3); + BSATN.NullableStringVariantRW.Write(writer, NullableStringVariant_); + } + public override string ToString() => $"NullableStringVariant({SpacetimeDB.BSATN.StringUtil.GenericToString(NullableStringVariant_)})"; } @@ -58,25 +86,7 @@ public CustomTaggedEnum Read(System.IO.BinaryReader reader) public void Write(System.IO.BinaryWriter writer, CustomTaggedEnum value) { - switch (value) - { - case IntVariant(var inner): - writer.Write((byte)0); - IntVariantRW.Write(writer, inner); - break; - case StringVariant(var inner): - writer.Write((byte)1); - StringVariantRW.Write(writer, inner); - break; - case NullableIntVariant(var inner): - writer.Write((byte)2); - NullableIntVariantRW.Write(writer, inner); - break; - case NullableStringVariant(var inner): - writer.Write((byte)3); - NullableStringVariantRW.Write(writer, inner); - break; - } + value.WriteFields(writer); } public SpacetimeDB.BSATN.AlgebraicType.Ref GetAlgebraicType( diff --git a/crates/bindings-csharp/Runtime/Http.cs b/crates/bindings-csharp/Runtime/Http.cs index 2567f4a11e5..227165c68ae 100644 --- a/crates/bindings-csharp/Runtime/Http.cs +++ b/crates/bindings-csharp/Runtime/Http.cs @@ -323,10 +323,7 @@ public Result Send(HttpRequest request) Version = ToWireVersion(request.Version), }; - var requestBytes = IStructuralReadWrite.ToBytes( - new HttpRequestWire.BSATN(), - requestWire - ); + var requestBytes = IStructuralWrite.ToBytes(requestWire); var bodyBytes = request.Body.ToBytes(); var status = FFI.procedure_http_request( diff --git a/crates/bindings-csharp/Runtime/Internal/IIndex.cs b/crates/bindings-csharp/Runtime/Internal/IIndex.cs index 33525924f2d..08e73aa8567 100644 --- a/crates/bindings-csharp/Runtime/Internal/IIndex.cs +++ b/crates/bindings-csharp/Runtime/Internal/IIndex.cs @@ -147,7 +147,7 @@ out var numDeleted protected Row DoUpdate(Row row) { // Insert the row. - var bytes = IStructuralReadWrite.ToBytes(row); + var bytes = IStructuralWrite.ToBytes(row); var bytes_len = (uint)bytes.Length; FFI.datastore_update_bsatn(ITableView.tableId, indexId, bytes, ref bytes_len); @@ -210,7 +210,7 @@ out var numDeleted protected Row DoUpdate(Row row) { // Insert the row. - var bytes = IStructuralReadWrite.ToBytes(row); + var bytes = IStructuralWrite.ToBytes(row); var bytes_len = (uint)bytes.Length; FFI.datastore_update_bsatn(ITableView.tableId, indexId, bytes, ref bytes_len); diff --git a/crates/bindings-csharp/Runtime/Internal/ITable.cs b/crates/bindings-csharp/Runtime/Internal/ITable.cs index a322216a1d3..3c555d59d36 100644 --- a/crates/bindings-csharp/Runtime/Internal/ITable.cs +++ b/crates/bindings-csharp/Runtime/Internal/ITable.cs @@ -171,7 +171,7 @@ protected static ulong DoCount() protected static T DoInsert(T row) { // Insert the row. - var bytes = IStructuralReadWrite.ToBytes(row); + var bytes = IStructuralWrite.ToBytes(row); var bytes_len = (uint)bytes.Length; FFI.datastore_insert_bsatn(tableId, bytes, ref bytes_len); diff --git a/crates/bindings-csharp/Runtime/Internal/Module.cs b/crates/bindings-csharp/Runtime/Internal/Module.cs index eebd573cfc5..7418f5f21f8 100644 --- a/crates/bindings-csharp/Runtime/Internal/Module.cs +++ b/crates/bindings-csharp/Runtime/Internal/Module.cs @@ -518,8 +518,8 @@ public static void __describe_module__(BytesSink description) try { var module = moduleDef.BuildModuleDefinition(); - RawModuleDef versioned = new RawModuleDef.V10(module); - var moduleBytes = IStructuralReadWrite.ToBytes(new RawModuleDef.BSATN(), versioned); + var versioned = new RawModuleDef.V10(module); + var moduleBytes = IStructuralWrite.ToBytes(versioned); description.Write(moduleBytes); } catch (Exception e) @@ -646,9 +646,7 @@ BytesSink responseBodySink var response = httpHandlers[(int)id] .Invoke(ctx, SpacetimeDB.HttpClient.FromWire(requestWire, requestBody.Consume())); var (responseWire, responseBody) = SpacetimeDB.HttpClient.ToWire(response); - responseSink.Write( - IStructuralReadWrite.ToBytes(new HttpResponseWire.BSATN(), responseWire) - ); + responseSink.Write(IStructuralWrite.ToBytes(responseWire)); responseBodySink.Write(responseBody); return Errno.OK;