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, #default_value, #message_class, #name, #rule, #tag, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseField

descriptor, #descriptor, #initialize, #initialized?, #max, #merge, #min, #optional?, #packed?, #ready?, #repeated?, #required?, #set, #to_s

Constructor Details

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

Class Method Details

.defaultObject



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

def self.default; 0.0; end

.maxObject



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

def self.max;  1.0/0; end

.minObject



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

def self.min; -1.0/0; end

Instance Method Details

#acceptable?(val) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (TypeError)


492
493
494
495
496
# File 'lib/protobuf/message/field.rb', line 492

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

#decode(bytes) ⇒ Object



484
485
486
# File 'lib/protobuf/message/field.rb', line 484

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

#encode(value) ⇒ Object



488
489
490
# File 'lib/protobuf/message/field.rb', line 488

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

#wire_typeObject



480
481
482
# File 'lib/protobuf/message/field.rb', line 480

def wire_type
  WireType::FIXED32
end