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
ruby changes #320
Comments
Hi @skippy,
Yes, we'd love a PR for that! They respond to
The append (
Did you mean to assign it (
This question was actually extensively discussed/debated internally when we designed the API, and in the end we disallowed it (and added The reason is the result of combining (i) the typechecking of list elements and (ii) principle of least surprise when the user holds aliases / multiple references to a list field. Consider what options we have if the user assigns a list If we do (2), then we've broken the typechecking that we do everywhere else. The user could assign an empty Ruby array If we do (1), then
So we can't do (1) either. Given that we can't do (1) or (2), and these are logically the only choices (in the "A or not A" sense) if we allow assignment of raw Ruby arrays to repeated fields, we concluded that we can't allow assignment of raw arrays to repeated fields. We nevertheless tried to make things a little more convenient where possible, which is why there is the There is also a |
Hi @cfallin, thank you for the thoughtful response! I understand about wanting to do typing at time of setting rather than at time of encode/decode. But I think having In other Protobuf libs, the repeated field is a wrapper/delegator around an array object. I think the same pattern could be applied here with success. The other approach is to write the syntactic sugar in regular ruby and not fix it in the c/java guts. This may be a tad more inefficient, but it could really help smooth out the duck typing. @cfallin, why don't I start sending in PRs with tests (see if I can get to it this weekend), and accept/deny/discuss as you and the team see fit. No harm if they are rejected :) I like this library quite a bit and I can always monkey patch in the syntactic sugar, myself, as needed. a few questions on submissions:
|
Hi @skippy, Yes, I think fleshing out the I saw your PRs -- I'll go review those now. Thanks! |
@cfallin thanks! |
I'll go ahead and close this issue since I think your PRs addressed your immediate concerns (?) but please do feel free to send more PRs if you have any other issues/improvements for the |
more on their way :) but leaving this closed sounds good |
…hmark Added a benchmark for ctype=STRING_PIECE
hello,
would you be open to the following changes:
message.repeated_field = [1,2,3]
Currently, this throws aTypeError: Expected repeated field array
message.repeated_field += []
. Currently, this throws aTypeError: Repeated field array has wrong message/enum class
#size
My caveat is that it has been 10+ yrs since I've done any C. these should be straight forward changes, but I may need a bit more of a review than normal :) With that said, if these changes are acceptable, I'll submit a PR
The text was updated successfully, but these errors were encountered: