-
Notifications
You must be signed in to change notification settings - Fork 26
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
Improve oneof
support
#40
base: master
Are you sure you want to change the base?
Commits on Jul 16, 2021
-
Given a message: ``` message Foo { oneof timestamp { int64 created; int64 updated; } } ``` Previously the generated classes by crystal-protoc-gen would allow to set multiple values of the oneof: ``` foo.created = 123 foo.updated = 345 foo.created # => 123 foo.updated # => 345 ``` With this patch the sibling oneof-values will be cleared when one is set: ``` foo.created = 123 foo.updated = 345 foo.created # => nil foo.updated # => 345 ``` Also when deserializing a message that contains oneofs there was previously no way of knowing which oneof value is populated. With this patch we synthesize a new instance variable by the name of the oneof to contain the string-name of the member that is populated: ``` foo.created = 123 foo.updated = 345 foo.created # => nil foo.updated # => 345 foo.timestamp # => "updated" foo[foo.timestamp] # => 345 ```
Configuration menu - View commit details
-
Copy full SHA for 82b2f40 - Browse repository at this point
Copy the full SHA 82b2f40View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7587e68 - Browse repository at this point
Copy the full SHA 7587e68View commit details
Commits on Jul 17, 2021
-
Fix potential clash with reserved keywords
Note: * This also changes the constructor semantics when multiple oneof-values are given (now the *first* value is kept instead of the last) * Using reserved keywords as protobuf field-names remains a bad idea regardless. For example a field called `delete` will break ts-proto / protoc-gen-js and probably others
Configuration menu - View commit details
-
Copy full SHA for 8035bd5 - Browse repository at this point
Copy the full SHA 8035bd5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 53df591 - Browse repository at this point
Copy the full SHA 53df591View commit details -
Configuration menu - View commit details
-
Copy full SHA for 0c22b97 - Browse repository at this point
Copy the full SHA 0c22b97View commit details -
Call setters after deserializing
Previously deserializing a message containing `oneofs` would not set the oneof instance var. E.g. you would get: `{ oneof_member1: 1, oneof_member_2: nil, my_oneof: nil }` Now it works as intended and you get: `{ oneof_member1: 1, oneof_member_2: nil, my_oneof: "oneof_member1" }`
Configuration menu - View commit details
-
Copy full SHA for 4e8c566 - Browse repository at this point
Copy the full SHA 4e8c566View commit details -
Configuration menu - View commit details
-
Copy full SHA for ca66c71 - Browse repository at this point
Copy the full SHA ca66c71View commit details
Commits on Jul 23, 2021
-
Add direct getter for oneof value
`myobj.myoneof_value` is more convenient than `myobj[myobj.myoneof]` esp. when dealing with nested objects.
Configuration menu - View commit details
-
Copy full SHA for 83296aa - Browse repository at this point
Copy the full SHA 83296aaView commit details
Commits on Jul 24, 2021
-
Restrict return type of oneof-by-name getter
The return-type of `myobj.myoneof_value` is now restricted to the types of the possible oneof-values. Previously it would include the types of *all* message-fields (even those that are not part of the queried oneof).
Configuration menu - View commit details
-
Copy full SHA for 93f3afc - Browse repository at this point
Copy the full SHA 93f3afcView commit details -
Fix return type restriction (String/Symbol mixup)
Now it should actually work. ;) Note: Resist the temptation to store ONEOF as Symbol's. It appears to work at first and saves some String-conversions but wreaks havoc when JSON::Serializable comes into play.
Configuration menu - View commit details
-
Copy full SHA for 8ae57a8 - Browse repository at this point
Copy the full SHA 8ae57a8View commit details
Commits on Jul 26, 2021
-
Configuration menu - View commit details
-
Copy full SHA for 2f015e4 - Browse repository at this point
Copy the full SHA 2f015e4View commit details