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, #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?, #clear, default, #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

Instance Method Details

#decode(bytes) ⇒ Object



369
370
371
372
373
# File 'lib/protobuf/message/field.rb', line 369

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

#encode(value) ⇒ Object



364
365
366
367
# File 'lib/protobuf/message/field.rb', line 364

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