-
Notifications
You must be signed in to change notification settings - Fork 9
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
make-structs cmd line option #15
Conversation
partial resolve #14 |
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.
This would be a good workaround till we find a solution to make struct/class
setting persistent (per
message definition) in the .proto
file.
Thank you for the PR!
examples/add_person.d
Outdated
@@ -9,7 +9,10 @@ import tutorial.addressbook; | |||
/// This function fills in a Person message based on user input. | |||
Person promptForAddress() | |||
{ | |||
auto person = new Person; | |||
static if (is(Person == class)) |
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.
Three times the same static if/else
, maybe a small template make!T
.
Ex.: auto person = make!Person
protoc_gen_d/protoc-gen-d.d
Outdated
result ~= "\n"; | ||
result ~= strIndent; | ||
result ~= indent > 0 ? "static " : ""; | ||
result ~= makeStructs ? "struct" : "class"; |
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 check here if the protobuf message definition is recursive. struct
cannot be used for recursive messages.
This should be check in the code generator, otherwise the user would need to deal with it at compile time, probably not knowing that the generated message definition is wrong.
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.
What you mean by recursive messages? A
in B
as field, and B
in A
as field, right?
Fields must be pointers in this case and there comes more difficult code for working with its (get address of stack variable is bad idea, need use GC for allocate memory, or any other variant). I think this case is example where structs are not suits.
Co-Authored-By: deviator <[email protected]>
Co-Authored-By: deviator <[email protected]>
No description provided.