Class: Protobuf::Field::SignedIntegerField
- Inherits:
-
VarintField
- Object
- BaseField
- VarintField
- Protobuf::Field::SignedIntegerField
- Defined in:
- lib/protobuf/message/field.rb
Overview
Base class for sint32 and sint64
Direct Known Subclasses
Constant Summary
Constants inherited from VarintField
VarintField::INT32_MAX, VarintField::INT32_MIN, VarintField::INT64_MAX, VarintField::INT64_MIN, VarintField::UINT32_MAX, VarintField::UINT64_MAX
Instance Attribute Summary
Attributes inherited from BaseField
#default, #default_value, #message_class, #name, #rule, #tag, #type
Instance Method Summary collapse
Methods inherited from VarintField
#acceptable?, decode, default, encode, #wire_type
Methods inherited from BaseField
#acceptable?, default, 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
Instance Method Details
#decode(value) ⇒ Object
448 449 450 451 452 453 454 |
# File 'lib/protobuf/message/field.rb', line 448 def decode(value) if (value & 1).zero? value >> 1 # positive value else ~value >> 1 # negative value end end |
#encode(value) ⇒ Object
456 457 458 459 460 461 462 |
# File 'lib/protobuf/message/field.rb', line 456 def encode(value) if value >= 0 VarintField.encode(value << 1) else VarintField.encode(~(value << 1)) end end |