Module: Gapic::Protobuf
- Defined in:
- lib/gapic/protobuf.rb
Overview
TODO: Describe Protobuf
Class Method Summary collapse
-
.coerce(hash, to:) ⇒ Object
Creates an instance of a protobuf message from a hash that may include nested hashes.
-
.time_to_timestamp(time) ⇒ Google::Protobuf::Timestamp
Utility for converting a Ruby Time instance to a Google::Protobuf::Timestamp.
-
.timestamp_to_time(timestamp) ⇒ Time
Utility for converting a Google::Protobuf::Timestamp instance to a Ruby time.
Class Method Details
.coerce(hash, to:) ⇒ Object
Creates an instance of a protobuf message from a hash that may include nested hashes. google/protobuf
allows
for the instantiation of protobuf messages using hashes but does not allow for nested hashes to instantiate
nested submessages.
31 32 33 34 35 36 37 38 39 |
# File 'lib/gapic/protobuf.rb', line 31 def self.coerce hash, to: return hash if hash.is_a? to # Sanity check: input must be a Hash raise ArgumentError, "Value #{hash} must be a Hash or a #{to.name}" unless hash.is_a? Hash hash = hash, to to.new hash end |
.time_to_timestamp(time) ⇒ Google::Protobuf::Timestamp
Utility for converting a Ruby Time instance to a Google::Protobuf::Timestamp.
146 147 148 |
# File 'lib/gapic/protobuf.rb', line 146 def self. time Google::Protobuf::Timestamp.new seconds: time.to_i, nanos: time.nsec end |
.timestamp_to_time(timestamp) ⇒ Time
Utility for converting a Google::Protobuf::Timestamp instance to a Ruby time.
136 137 138 |
# File 'lib/gapic/protobuf.rb', line 136 def self. Time.at .nanos * 10**-9 + .seconds end |