Class: Protobuf::Field::SignedIntegerField
- Inherits:
-
VarintField
- Object
- BaseField
- VarintField
- Protobuf::Field::SignedIntegerField
- Defined in:
- lib/protobuf/field/signed_integer_field.rb
Direct Known Subclasses
Constant Summary
Constants inherited from VarintField
VarintField::CACHE_LIMIT, VarintField::INT32_MAX, VarintField::INT32_MIN, VarintField::INT64_MAX, VarintField::INT64_MIN, VarintField::UINT32_MAX, VarintField::UINT64_MAX
Constants inherited from BaseField
Instance Attribute Summary
Attributes inherited from BaseField
#fully_qualified_name, #message_class, #name, #options, #rule, #tag, #type_class
Instance Method Summary collapse
-
#decode(value) ⇒ Object
Public Instance Methods.
- #encode(value) ⇒ Object
Methods inherited from VarintField
#acceptable?, cached_varint, #coerce!, default, encode, #wire_type
Methods inherited from BaseField
#acceptable?, #coerce!, default, #default, #default_value, #deprecated?, #enum?, #extension?, #fully_qualified_name_only!, #initialize, #message?, #optional?, #packed?, #repeated?, #repeated_message?, #required?, #set, #tag_encoded, #to_s, #wire_type
Methods included from Logging
initialize_logger, #log_exception, #log_signature, #logger, #sign_message
Constructor Details
This class inherits a constructor from Protobuf::Field::BaseField
Instance Method Details
#decode(value) ⇒ Object
Public Instance Methods
11 12 13 14 15 16 17 |
# File 'lib/protobuf/field/signed_integer_field.rb', line 11 def decode(value) if (value & 1).zero? value >> 1 # positive value else ~value >> 1 # negative value end end |
#encode(value) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/protobuf/field/signed_integer_field.rb', line 19 def encode(value) if value >= 0 VarintField.encode(value << 1) else VarintField.encode(~(value << 1)) end end |