Module: GBTiles::DataType

Defined in:
lib/gbtiles/helpers/data_type.rb

Class Method Summary collapse

Class Method Details

.boolean(src) ⇒ Object

BOOLEAN 1 BYTE



62
63
64
# File 'lib/gbtiles/helpers/data_type.rb', line 62

def self.boolean src
  src.slice!(0, 1).unpack("C")[0].eql? 1
end

.boolean!(src) ⇒ Object



66
67
68
# File 'lib/gbtiles/helpers/data_type.rb', line 66

def self.boolean! src
  self.boolean(src.slice!(0, 1))
end

.bword(src) ⇒ Object

BWORD BIG ENDIAN 2 BYTES



84
85
86
# File 'lib/gbtiles/helpers/data_type.rb', line 84

def self.bword src
  src.slice(0, 2).unpack("n*")[0]
end

.bword!(src) ⇒ Object



88
89
90
# File 'lib/gbtiles/helpers/data_type.rb', line 88

def self.bword! src
  self.bword(src.slice!(0, 2))
end

.byte(src) ⇒ Object

BYTE 1 BYTE



52
53
54
# File 'lib/gbtiles/helpers/data_type.rb', line 52

def self.byte src
  src.slice(0, 1).unpack("C*")[0]
end

.byte!(src) ⇒ Object



56
57
58
# File 'lib/gbtiles/helpers/data_type.rb', line 56

def self.byte! src
  self.byte(src.slice!(0, 1))
end

.long(src) ⇒ Object

LITTLE ENDIAN 32 BIT INTEGER 4 BYTES



73
74
75
# File 'lib/gbtiles/helpers/data_type.rb', line 73

def self.long src
  src.slice(0, 4).unpack("V*")[0]
end

.long!(src) ⇒ Object



77
78
79
# File 'lib/gbtiles/helpers/data_type.rb', line 77

def self.long! src
  self.long(src.slice!(0, 4))
end

.string(src, length = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gbtiles/helpers/data_type.rb', line 3

def self.string src, length = nil
  if src.nil? then
    return nil
  end

  if !length.nil? then
    string = src.slice(0, length)
  else
    string = src
  end

  if !string.nil? then
    string = string.split(/\0/).first
  end

  if !string.nil? then
    string = string.unpack("A*")[0]
  end

  string
end

.string!(src, length = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gbtiles/helpers/data_type.rb', line 25

def self.string! src, length = nil
  if src.nil? then
    return nil
  end

  if !length.nil? then
    string = src.slice!(0, length)
  else 
    string = src
  end

  self.string(string, length)
end

.word(src) ⇒ Object

WORD LITTLE ENDIAN 2 BYTES



42
43
44
# File 'lib/gbtiles/helpers/data_type.rb', line 42

def self.word src
  src.slice(0, 2).unpack("v*")[0]
end

.word!(src) ⇒ Object



46
47
48
# File 'lib/gbtiles/helpers/data_type.rb', line 46

def self.word! src
  self.word(src.slice!(0, 2))
end