module GBTiles::DataType

Public Class Methods

boolean(src) click to toggle source

BOOLEAN 1 BYTE

# 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) click to toggle source
# File lib/gbtiles/helpers/data_type.rb, line 66
def self.boolean! src
  self.boolean(src.slice!(0, 1))
end
bword(src) click to toggle source

BWORD BIG ENDIAN 2 BYTES

# File lib/gbtiles/helpers/data_type.rb, line 84
def self.bword src
  src.slice(0, 2).unpack("n*")[0]
end
bword!(src) click to toggle source
# File lib/gbtiles/helpers/data_type.rb, line 88
def self.bword! src
  self.bword(src.slice!(0, 2))
end
byte(src) click to toggle source

BYTE 1 BYTE

# File lib/gbtiles/helpers/data_type.rb, line 52
def self.byte src
  src.slice(0, 1).unpack("C*")[0]
end
byte!(src) click to toggle source
# File lib/gbtiles/helpers/data_type.rb, line 56
def self.byte! src
  self.byte(src.slice!(0, 1))
end
long(src) click to toggle source

LITTLE ENDIAN 32 BIT INTEGER 4 BYTES

# File lib/gbtiles/helpers/data_type.rb, line 73
def self.long src
  src.slice(0, 4).unpack("V*")[0]
end
long!(src) click to toggle source
# File lib/gbtiles/helpers/data_type.rb, line 77
def self.long! src
  self.long(src.slice!(0, 4))
end
string(src, length = nil) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

WORD LITTLE ENDIAN 2 BYTES

# File lib/gbtiles/helpers/data_type.rb, line 42
def self.word src
  src.slice(0, 2).unpack("v*")[0]
end
word!(src) click to toggle source
# File lib/gbtiles/helpers/data_type.rb, line 46
def self.word! src
  self.word(src.slice!(0, 2))
end