Class: Protobuf::Field::IntegerField

Inherits:
VarintField show all
Defined in:
lib/protobuf/message/field.rb

Overview

Base class for int32 and int64

Direct Known Subclasses

Int32Field, Int64Field

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



420
421
422
423
# File 'lib/protobuf/message/field.rb', line 420

def decode(value)
  value -= 0x1_0000_0000_0000_0000 if (value & 0x8000_0000_0000_0000).nonzero?
  value
end

#encode(value) ⇒ Object



415
416
417
418
# File 'lib/protobuf/message/field.rb', line 415

def encode(value)
  # original Google's library uses 64bits integer for negative value
  VarintField.encode(value & 0xffff_ffff_ffff_ffff)
end