Class: Innodb::DataType::IntegerType

Inherits:
Object
  • Object
show all
Defined in:
lib/innodb/data_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_type, modifiers, properties) ⇒ IntegerType

Returns a new instance of IntegerType.



31
32
33
34
35
# File 'lib/innodb/data_type.rb', line 31

def initialize(base_type, modifiers, properties)
  @width = base_type_width_map[base_type]
  @unsigned = properties.include?(:UNSIGNED)
  @name = Innodb::DataType.make_name(base_type, modifiers, properties)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



28
29
30
# File 'lib/innodb/data_type.rb', line 28

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



29
30
31
# File 'lib/innodb/data_type.rb', line 29

def width
  @width
end

Instance Method Details

#base_type_width_mapObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/innodb/data_type.rb', line 37

def base_type_width_map
  {
    BOOL: 1,
    BOOLEAN: 1,
    TINYINT: 1,
    SMALLINT: 2,
    MEDIUMINT: 3,
    INT: 4,
    INT6: 6,
    BIGINT: 8,
  }
end

#get_int(data, nbits) ⇒ Object



59
60
61
# File 'lib/innodb/data_type.rb', line 59

def get_int(data, nbits)
  BinData.const_get("Int%dbe" % nbits).read(data) ^ (-1 << (nbits - 1))
end

#get_uint(data, nbits) ⇒ Object



55
56
57
# File 'lib/innodb/data_type.rb', line 55

def get_uint(data, nbits)
  BinData.const_get("Uint%dbe" % nbits).read(data)
end

#value(data) ⇒ Object



50
51
52
53
# File 'lib/innodb/data_type.rb', line 50

def value(data)
  nbits = @width * 8
  @unsigned ? get_uint(data, nbits) : get_int(data, nbits)
end