-
Notifications
You must be signed in to change notification settings - Fork 15.5k
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
Implemented proto3 presence for Ruby. #7406
Changes from all commits
85ab82a
58b5df3
e777519
dca82c8
054a686
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 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -242,9 +242,14 @@ static int extract_method_call(VALUE method_name, MessageHeader* self, | |||||||||||||
// Method calls like 'has_foo?' are not allowed if field "foo" does not have | ||||||||||||||
// a hasbit (e.g. repeated fields or non-message type fields for proto3 | ||||||||||||||
// syntax). | ||||||||||||||
if (accessor_type == METHOD_PRESENCE && test_f != NULL && | ||||||||||||||
!upb_fielddef_haspresence(test_f)) { | ||||||||||||||
return METHOD_UNKNOWN; | ||||||||||||||
if (accessor_type == METHOD_PRESENCE && test_f != NULL) { | ||||||||||||||
if (!upb_fielddef_haspresence(test_f)) return METHOD_UNKNOWN; | ||||||||||||||
|
||||||||||||||
// TODO(haberman): remove this case, allow for proto3 oneofs. | ||||||||||||||
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. Do we previously support this? 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. No, we have never supported this. The unit tests were failing until I added this check, see: Lines 45 to 50 in 1895045
|
||||||||||||||
if (upb_fielddef_realcontainingoneof(test_f) && | ||||||||||||||
upb_filedef_syntax(upb_fielddef_file(test_f)) == UPB_SYNTAX_PROTO3) { | ||||||||||||||
return METHOD_UNKNOWN; | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
*o = test_o; | ||||||||||||||
|
@@ -605,18 +610,18 @@ VALUE Message_inspect(VALUE _self) { | |||||||||||||
*/ | ||||||||||||||
VALUE Message_to_h(VALUE _self) { | ||||||||||||||
MessageHeader* self; | ||||||||||||||
VALUE hash; | ||||||||||||||
VALUE hash = rb_hash_new(); | ||||||||||||||
upb_msg_field_iter it; | ||||||||||||||
bool is_proto2; | ||||||||||||||
TypedData_Get_Struct(_self, MessageHeader, &Message_type, self); | ||||||||||||||
|
||||||||||||||
// We currently have a few behaviors that are specific to proto2. | ||||||||||||||
// This is unfortunate, we should key behaviors off field attributes (like | ||||||||||||||
// whether a field has presence), not proto2 vs. proto3. We should see if we | ||||||||||||||
// can change this without breaking users. | ||||||||||||||
bool is_proto2 = | ||||||||||||||
is_proto2 = | ||||||||||||||
upb_msgdef_syntax(self->descriptor->msgdef) == UPB_SYNTAX_PROTO2; | ||||||||||||||
|
||||||||||||||
hash = rb_hash_new(); | ||||||||||||||
|
||||||||||||||
for (upb_msg_field_begin(&it, self->descriptor->msgdef); | ||||||||||||||
!upb_msg_field_done(&it); | ||||||||||||||
upb_msg_field_next(&it)) { | ||||||||||||||
|
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.
Will this renaming suddenly change when users reorder fields in their proto definition?
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.
If there are conflicts it could. But the synthetic oneof name was not created by the user, so the user cannot assume what its name is.