Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1162,8 +1162,11 @@ public byte[] Invoke(
PublicTable.BSATN
>.GetListSerializer();
var listValue = ModuleRegistration.ToListOrEmpty(returnValue);
var header = new global::SpacetimeDB.Internal.ViewResultHeader.RowData(default);
var headerRW = new global::SpacetimeDB.Internal.ViewResultHeader.BSATN();
using var output = new System.IO.MemoryStream();
using var writer = new System.IO.BinaryWriter(output);
headerRW.Write(writer, header);
listSerializer.Write(writer, listValue);
return output.ToArray();
}
Expand Down Expand Up @@ -1208,8 +1211,11 @@ public byte[] Invoke(
PublicTable.BSATN
>.GetListSerializer();
var listValue = ModuleRegistration.ToListOrEmpty(returnValue);
var header = new global::SpacetimeDB.Internal.ViewResultHeader.RowData(default);
var headerRW = new global::SpacetimeDB.Internal.ViewResultHeader.BSATN();
using var output = new System.IO.MemoryStream();
using var writer = new System.IO.BinaryWriter(output);
headerRW.Write(writer, header);
listSerializer.Write(writer, listValue);
return output.ToArray();
}
Expand Down
6 changes: 6 additions & 0 deletions crates/bindings-csharp/Codegen/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,15 +1039,21 @@ public string GenerateDispatcherClass(uint index)
? $$$"""
var listSerializer = {{{ReturnType.BSATNName}}}.GetListSerializer();
var listValue = ModuleRegistration.ToListOrEmpty(returnValue);
var header = new global::SpacetimeDB.Internal.ViewResultHeader.RowData(default);
var headerRW = new global::SpacetimeDB.Internal.ViewResultHeader.BSATN();
using var output = new System.IO.MemoryStream();
using var writer = new System.IO.BinaryWriter(output);
headerRW.Write(writer, header);
listSerializer.Write(writer, listValue);
return output.ToArray();
"""
: $$$"""
{{{ReturnType.BSATNName}}} returnRW = new();
var header = new global::SpacetimeDB.Internal.ViewResultHeader.RowData(default);
var headerRW = new global::SpacetimeDB.Internal.ViewResultHeader.BSATN();
using var output = new System.IO.MemoryStream();
using var writer = new System.IO.BinaryWriter(output);
headerRW.Write(writer, header);
returnRW.Write(writer, returnValue);
return output.ToArray();
""";
Expand Down
48 changes: 46 additions & 2 deletions crates/bindings-csharp/Runtime/Internal/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@
catch (Exception e)
{
var error_str = e.Message ?? e.GetType().FullName;
var error_bytes = System.Text.Encoding.UTF8.GetBytes(error_str);

Check warning on line 316 in crates/bindings-csharp/Runtime/Internal/Module.cs

View workflow job for this annotation

GitHub Actions / unity-testsuite

Possible null reference argument for parameter 's' in 'byte[] Encoding.GetBytes(string s)'.

Check warning on line 316 in crates/bindings-csharp/Runtime/Internal/Module.cs

View workflow job for this annotation

GitHub Actions / csharp-testsuite

Possible null reference argument for parameter 's' in 'byte[] Encoding.GetBytes(string s)'.
error.Write(error_bytes);
return Errno.HOST_CALL_FAILURE;
}
Expand Down Expand Up @@ -366,6 +366,30 @@
}
}

/// <summary>
/// Called by the host to execute a view when the sender calls the view identified by <paramref name="id" />.
/// </summary>
/// <remarks>
/// <para>
/// The sender identity is passed as 4 <see cref="ulong" /> values (<paramref name="sender_0" /> through
/// <paramref name="sender_3" />) representing a little-endian <see cref="SpacetimeDB.Identity" />.
/// </para>
/// <para>
/// <paramref name="args" /> is a host-registered <see cref="BytesSource" /> containing the BSATN-encoded
/// view arguments. For empty arguments, <paramref name="args" /> will be invalid.
/// </para>
/// <para>
/// The view output is written to <paramref name="rows" />, a host-registered <see cref="BytesSink" />.
/// </para>
/// <para>
/// Note: a previous view ABI wrote the return rows directly to the sink.
/// The current ABI writes a BSATN-encoded <see cref="ViewResultHeader" /> first, in order to distinguish
/// between views that return row data and views that return queries.
/// </para>
/// <para>
/// The current ABI is identified by returning error code <c>2</c>.
/// </para>
/// </remarks>
public static Errno __call_view__(
uint id,
ulong sender_0,
Expand All @@ -386,7 +410,7 @@
using var reader = new BinaryReader(stream);
var bytes = viewDispatchers[(int)id].Invoke(reader, ctx);
rows.Write(bytes);
return Errno.OK;
return (Errno)2;
}
catch (Exception e)
{
Expand All @@ -395,6 +419,26 @@
}
}

/// <summary>
/// Called by the host to execute an anonymous view.
/// </summary>
/// <remarks>
/// <para>
/// <paramref name="args" /> is a host-registered <see cref="BytesSource" /> containing the BSATN-encoded
/// view arguments. For empty arguments, <paramref name="args" /> will be invalid.
/// </para>
/// <para>
/// The view output is written to <paramref name="rows" />, a host-registered <see cref="BytesSink" />.
/// </para>
/// <para>
/// Note: a previous view ABI wrote the return rows directly to the sink.
/// The current ABI writes a BSATN-encoded <see cref="ViewResultHeader" /> first, in order to distinguish
/// between views that return row data and views that return queries.
/// </para>
/// <para>
/// The current ABI is identified by returning error code <c>2</c>.
/// </para>
/// </remarks>
public static Errno __call_view_anon__(uint id, BytesSource args, BytesSink rows)
{
try
Expand All @@ -404,7 +448,7 @@
using var reader = new BinaryReader(stream);
var bytes = anonymousViewDispatchers[(int)id].Invoke(reader, ctx);
rows.Write(bytes);
return Errno.OK;
return (Errno)2;
}
catch (Exception e)
{
Expand Down
5 changes: 5 additions & 0 deletions crates/bindings-csharp/Runtime/Internal/ViewResultHeader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace SpacetimeDB.Internal;

[SpacetimeDB.Type]
public partial record ViewResultHeader
: SpacetimeDB.TaggedEnum<(SpacetimeDB.Unit RowData, string RawSql)>;
Loading