Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protobufectomy: c# codegen #1466

Open
wants to merge 3 commits into
base: noa/protobufectomy
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions crates/cli/src/subcommands/generate/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ fn autogen_csharp_product_table_common(
let mut output = CsharpAutogen::new(
namespace,
&[
"SpacetimeDB.ClientApi",
"System.Collections.Generic",
"System.Linq",
"System.Runtime.Serialization",
Expand Down Expand Up @@ -647,7 +648,7 @@ pub fn autogen_csharp_globals(items: &[GenItem], namespace: &str) -> Vec<(String
);
writeln!(
output,
"public ReducerEvent(ClientApi.Event dbEvent, IReducerArgs? args) : base(dbEvent) => Args = args;"
"public ReducerEvent(TransactionUpdate update, IReducerArgs? args) : base(update) => Args = args;"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either we need to add using SpacetimeDB.ClientApi; to the top of this file or you need to fully qualify this path because it causes a compilation issue:

Assets/_Project/autogen/_Globals/SpacetimeDBClient.cs(515,23): error CS0246: The type or namespace name 'TransactionUpdate' could not be found (are you missing a using directive or an assembly reference?)

);
writeln!(output);
// Properties for reducer args
Expand Down Expand Up @@ -694,18 +695,18 @@ pub fn autogen_csharp_globals(items: &[GenItem], namespace: &str) -> Vec<(String

writeln!(
output,
"protected override ReducerEvent ReducerEventFromDbEvent(ClientApi.Event dbEvent)"
"protected override ReducerEvent ReducerEventFromDbEvent(TransactionUpdate update)"
);
indented_block(output, |output| {
writeln!(output, "var argBytes = dbEvent.FunctionCall.ArgBytes;");
writeln!(output, "IReducerArgs? args = dbEvent.FunctionCall.Reducer switch {{");
writeln!(output, "var encodedArgs = update.ReducerCall.Args;");
writeln!(output, "IReducerArgs? args = update.ReducerCall.ReducerName switch {{");
{
indent_scope!(output);
for (reducer, reducer_name) in std::iter::zip(&reducers, &reducer_names) {
let reducer_str_name = &reducer.name;
writeln!(
output,
"\"{reducer_str_name}\" => BSATNHelpers.FromProtoBytes<{reducer_name}ArgsStruct>(argBytes),"
"\"{reducer_str_name}\" => BSATNHelpers.Decode<{reducer_name}ArgsStruct>(encodedArgs),"
);
}
writeln!(output, "\"<none>\" => null,");
Expand All @@ -715,7 +716,7 @@ pub fn autogen_csharp_globals(items: &[GenItem], namespace: &str) -> Vec<(String
);
}
writeln!(output, "}};");
writeln!(output, "return new ReducerEvent(dbEvent, args);");
writeln!(output, "return new ReducerEvent(update, args);");
});
});

Expand Down
Loading