Module: ArrPM::V2::Tag::Type

Defined in:
lib/arr-pm/v2/tag.rb

Constant Summary collapse

NULL =
0
CHAR =
1
INT8 =
2
INT16 =
3
INT32 =
4
INT64 =
5
STRING =
6
BINARY =
7
STRING_ARRAY =
8
I18NSTRING =
9
TYPE_MAP =
Hash[constants.collect { |c| [const_get(c), c]

Class Method Summary collapse

Class Method Details

.parse(data, type, offset, count) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/arr-pm/v2/tag.rb', line 18

def self.parse(data, type, offset, count)
  case type
    when NULL
      nil
    when CHAR
      data[offset, count].unpack("A#{count}")
    when INT8
      data[offset, count].unpack("C" * count)
    when INT16
      data[offset, 2 * count].unpack("n" * count)
    when INT32
      data[offset, 4 * count].unpack("N" * count)
    when INT64
      a, b = data[offset, 8].unpack("NN")
      a << 32 + b
    when STRING, I18NSTRING
      data[offset..-1][/^[^\0]*/]
    when BINARY
      data[offset, count]
    when STRING_ARRAY
      data[offset..-1].split("\0")[0...count]
    else
      raise ArrPM::V2::Error::InvalidType, type
  end
end