-
Notifications
You must be signed in to change notification settings - Fork 103
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
base: noa/protobufectomy
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,8 +312,8 @@ fn autogen_csharp_product_table_common( | |
], | ||
); | ||
|
||
writeln!(output, "[SpacetimeDB.Type]"); | ||
writeln!(output, "[DataContract]"); | ||
writeln!(output, "[SpacetimeDB.Type]"); | ||
write!(output, "public partial class {name}"); | ||
if let Some(schema) = &schema { | ||
write!( | ||
|
@@ -328,7 +328,9 @@ fn autogen_csharp_product_table_common( | |
} | ||
writeln!(output); | ||
indented_block(&mut output, |output| { | ||
for field in &*product_type.elements { | ||
let num_fields = product_type.elements.len(); | ||
for i in 0..num_fields { | ||
let field = &product_type.elements[i]; | ||
let field_name = field | ||
.name | ||
.as_ref() | ||
|
@@ -343,11 +345,14 @@ fn autogen_csharp_product_table_common( | |
field_name.to_case(Case::Pascal), | ||
default_init(ctx, &field.algebraic_type) | ||
); | ||
if i + 1 != num_fields { | ||
writeln!(output); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is causing an additional space in between each field, do we need this change? This is causing the diff for the API upgrade to be pretty insane: https://github.com/clockworklabs/BitCraftClient/pull/3586/files There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right, I added this to make the emitted fields more readable, as the lines can get long. It's not a needed change tho, purely style. Should we keep or remove it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove it, if you feel strongly about the style change we can do it in a separate PR IMO - I just want the API upgrade to be as simple as possible. |
||
} | ||
} | ||
writeln!(output); | ||
|
||
// If this is a table, we want to generate event accessor and indexes | ||
if let Some(schema) = &schema { | ||
writeln!(output); | ||
let constraints = schema.column_constraints(); | ||
let mut unique_indexes = Vec::new(); | ||
// Declare custom index dictionaries | ||
|
@@ -647,7 +652,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;" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either we need to add
|
||
); | ||
writeln!(output); | ||
// Properties for reducer args | ||
|
@@ -694,18 +699,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,"); | ||
|
@@ -715,7 +720,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);"); | ||
}); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this transposition