-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Add support for descriptor options in ruby interface #12828
Closed
jsteinberg
wants to merge
6
commits into
protocolbuffers:main
from
jsteinberg:add-support-for-options-in-ruby
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d5ed3dd
Add support for descriptor options in ruby interface
jsteinberg 71f7226
DRY converting serialized options into ruby object
jsteinberg 04758ed
make serialized_options methods private
jsteinberg 188f456
Options messages should recursively freeze (deep_freeze)
jsteinberg 730fb06
Message internal_deep_freeze now recurses over repeated/map value fields
jsteinberg 10b3e2b
Fix spelling issue (Deeep -> Deep)
jsteinberg File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -905,6 +905,33 @@ static VALUE Message_freeze(VALUE _self) { | |
return _self; | ||
} | ||
|
||
/* | ||
* call-seq: | ||
* Message.deep_freeze => self | ||
* | ||
* Deeep freezes the message object recursively. | ||
*/ | ||
static VALUE Message_deep_freeze(VALUE _self) { | ||
Message* self = ruby_to_Message(_self); | ||
if (!RB_OBJ_FROZEN(_self)) { | ||
Message_freeze(_self); | ||
|
||
int n = upb_MessageDef_FieldCount(self->msgdef); | ||
for (int i = 0; i < n; i++) { | ||
const upb_FieldDef* f = upb_MessageDef_Field(self->msgdef, i); | ||
VALUE field = Message_getfield(_self, f); | ||
|
||
if (upb_FieldDef_IsMap(f) || upb_FieldDef_IsRepeated(f)) { | ||
rb_funcall(field, rb_intern("freeze"), 0); | ||
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. Repeated fields and maps can contain messages, so we will need them to support |
||
} else if (upb_FieldDef_IsSubMessage(f)) { | ||
Message_deep_freeze(field); | ||
} | ||
} | ||
} | ||
|
||
return _self; | ||
} | ||
|
||
/* | ||
* call-seq: | ||
* Message.[](index) => value | ||
|
@@ -1407,6 +1434,7 @@ static void Message_define_class(VALUE klass) { | |
rb_define_method(klass, "==", Message_eq, 1); | ||
rb_define_method(klass, "eql?", Message_eq, 1); | ||
rb_define_method(klass, "freeze", Message_freeze, 0); | ||
rb_define_private_method(klass, "deep_freeze", Message_deep_freeze, 0); | ||
rb_define_method(klass, "hash", Message_hash, 0); | ||
rb_define_method(klass, "to_h", Message_to_h, 0); | ||
rb_define_method(klass, "inspect", Message_inspect, 0); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let's call it
internal_deep_freeze
just so it's unambiguous that it's intended to be internal-only.It doesn't make it harder to call, but if someone does call it they will know that it's an API that could change.