Skip to content
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 native type setters for Timestamp and Duration in Ruby #5751

Merged
merged 13 commits into from
Mar 26, 2019

Conversation

jbolinger
Copy link
Contributor

Resolves #3121 by adding additional setters for fields of type Google::Protobuf::Timestamp and Google::Protobuf::Duration.

This allows a message with a Timestamp field to be set via:

my_message.timestamp = Time.at(1)
my_message.timestamp
# => <Google::Protobuf::Timestamp: seconds: 1, nanos: 0>

Similarly, for Duration fields:

MyMessage.new(duration: 1.1)
# => MyMessage: duration: <Google::Protobuf::Duration: seconds: 1, nanos: 100000000>>

ruby/tests/common_tests.rb Show resolved Hide resolved
ruby/tests/common_tests.rb Show resolved Hide resolved
char* value_type_name = rb_class2name(CLASS_OF(value));

// Time -> Google::Protobuf::Timestamp
if (strcmp(field_type_name, "Google::Protobuf::Timestamp") == 0 &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upb provides upb_msgdef_wellknowntype. You don't need strcmp here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I couldn't find too many usages of that method. How can I get the upb_msgdef from the type_class in order to use it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.. seems you cannot get msgdef from type_class

@TeBoring
Copy link
Contributor

Please sync

@TeBoring
Copy link
Contributor

Is there native types for duration in ruby?

@jbolinger
Copy link
Contributor Author

@TeBoring I've sync'd this with master.

@TeBoring
Copy link
Contributor

TeBoring commented Mar 2, 2019

It needs to be synced again.

@jbolinger
Copy link
Contributor Author

@TeBoring sync'd.

@jbolinger
Copy link
Contributor Author

@TeBoring any updates on this?

@TeBoring TeBoring merged commit d2daa38 into protocolbuffers:master Mar 26, 2019
@jbolinger jbolinger deleted the ruby-timewarp branch March 26, 2019 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants