module Google::Cloud::Bigtable::Convert
@private Helper module for converting Bigtable
values.
Public Instance Methods
duration_to_number(duration)
click to toggle source
Convert
protobuf durations to float.
@param duration [Google::Protobuf::Duration, nil] @return [Float, Integer, nil] Seconds with nano seconds
# File lib/google/cloud/bigtable/convert.rb, line 50 def duration_to_number duration return unless duration return duration.seconds if duration.nanos.zero? duration.seconds + (duration.nanos / 1_000_000_000.0) end
integer_to_signed_be_64(value)
click to toggle source
Converts an Integer to 64-bit signed big-endian integer data. Returns a string argument unchanged.
@param value [String, Integer] @return [String]
# File lib/google/cloud/bigtable/convert.rb, line 88 def integer_to_signed_be_64 value return [value].pack "q>" if value.is_a? Integer value end
number_to_duration(number)
click to toggle source
Convert
number to protobuf duration.
@param number [Float] Seconds with nano seconds @return [Google::Protobuf::Duration, nil]
# File lib/google/cloud/bigtable/convert.rb, line 35 def number_to_duration number return unless number Google::Protobuf::Duration.new( seconds: number.to_i, nanos: (number.remainder(1) * 1_000_000_000).round ) end
time_to_timestamp(time)
click to toggle source
Convert
time to timestamp protobuf object.
@param time [Time] @return [Google::Protobuf::Timestamp, nil]
# File lib/google/cloud/bigtable/convert.rb, line 75 def time_to_timestamp time return unless time Google::Protobuf::Timestamp.new seconds: time.to_i, nanos: time.nsec end
timestamp_to_time(timestamp)
click to toggle source
Convert
protobuf timestamp to Time object.
@param timestamp [Google::Protobuf::Timestamp] @return [Time, nil]
# File lib/google/cloud/bigtable/convert.rb, line 63 def timestamp_to_time timestamp return unless timestamp Time.at timestamp.seconds, timestamp.nanos / 1000.0 end