Class: DataTypes::UInt16

Inherits:
Type
  • Object
show all
Defined in:
lib/active_model_serializers_binary/data_types.rb

Instance Attribute Summary

Attributes inherited from Type

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

Instance Method Summary collapse

Methods inherited from Type

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

Constructor Details

#initialize(options = {}) ⇒ UInt16

Returns a new instance of UInt16.



54
55
56
# File 'lib/active_model_serializers_binary/data_types.rb', line 54

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

Instance Method Details

#dump(value = nil) ⇒ Object



58
59
60
61
# File 'lib/active_model_serializers_binary/data_types.rb', line 58

def dump(value=nil)
  before_dump( value )
  @raw_value = @value.pack('v*').unpack('C*')
end

#load(raw_value) ⇒ Object



63
64
65
66
67
# File 'lib/active_model_serializers_binary/data_types.rb', line 63

def load(raw_value)
  @raw_value = check_raw_value(raw_value)
  self.value = @raw_value.pack('C*').unpack('v*')
  after_load
end