Class: Protobuf::Field::FloatField

Inherits:
BaseField
  • Object
show all
Defined in:
lib/protobuf/message/field.rb

Direct Known Subclasses

DoubleField

Instance Attribute Summary

Attributes inherited from BaseField

#default, #message_class, #name, #rule, #tag, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseField

#clear, #default_value, #descriptor, descriptor, #error_message, #get, #initialize, #initialized?, #max, #merge, #merge_array, #merge_value, #min, #optional?, #ready?, #repeated?, #required?, #set, #to_s, #typed_default_value

Constructor Details

This class inherits a constructor from Protobuf::Field::BaseField

Class Method Details

.defaultObject



427
# File 'lib/protobuf/message/field.rb', line 427

def self.default; 0.0; end

.maxObject



428
# File 'lib/protobuf/message/field.rb', line 428

def self.max;  1.0/0; end

.minObject



429
# File 'lib/protobuf/message/field.rb', line 429

def self.min; -1.0/0; end

Instance Method Details

#acceptable?(val) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (TypeError)


443
444
445
446
447
# File 'lib/protobuf/message/field.rb', line 443

def acceptable?(val)
  raise TypeError.new(val.class.name) unless val.is_a? Numeric
  raise RangeError.new(val) if val < min or max < val
  true
end

#decode(bytes) ⇒ Object



435
436
437
# File 'lib/protobuf/message/field.rb', line 435

def decode(bytes)
  bytes.unpack('e').first
end

#encode(value) ⇒ Object



439
440
441
# File 'lib/protobuf/message/field.rb', line 439

def encode(value)
  [value].pack('e')
end

#wire_typeObject



431
432
433
# File 'lib/protobuf/message/field.rb', line 431

def wire_type
  Protobuf::WireType::FIXED32
end