Class: DataTypes::Int32

Inherits:
BaseType show all
Defined in:
lib/active_model_serializers_binary/data_types.rb

Instance Attribute Summary

Attributes inherited from BaseType

#bit_length, #count, #endianess, #length, #name, #parent, #raw_value, #sign, #type, #value

Instance Method Summary collapse

Methods inherited from BaseType

#after_load, #before_dump, #check, #check_raw_value, #check_value, #size, #to_s, #trim

Constructor Details

#initialize(options = {}) ⇒ Int32

Returns a new instance of Int32.



46
47
48
# File 'lib/active_model_serializers_binary/data_types.rb', line 46

def initialize(options = {})
  super options.merge :bit_length => 32, :sign => :signed
end

Instance Method Details

#dump(value = nil) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/active_model_serializers_binary/data_types.rb', line 50

def dump(value=nil)
  before_dump( value )
  if @endianess == :big
    @raw_value = @value.pack('l>*').unpack('C*')
  else
    @raw_value = @value.pack('l<*').unpack('C*')
  end
end

#load(raw_value) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/active_model_serializers_binary/data_types.rb', line 59

def load(raw_value)
  if @endianess == :big
    self.value = check_raw_value(raw_value).pack('C*').unpack('l>*') if !value.nil?
  else
    self.value = check_raw_value(raw_value).pack('C*').unpack('l<*') if !value.nil?
  end
  after_load
end