Module: RocketAMF::Pure::ReadIOHelpers

Included in:
Deserializer, Envelope
Defined in:
lib/rocketamf/pure/io_helpers.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#byte_orderObject



30
31
32
33
34
35
36
# File 'lib/rocketamf/pure/io_helpers.rb', line 30

def byte_order
  if [0x12345678].pack("L") == "\x12\x34\x56\x78"
    :BigEndian
  else
    :LittleEndian
  end
end

#byte_order_little?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/rocketamf/pure/io_helpers.rb', line 38

def byte_order_little?
  (byte_order == :LittleEndian) ? true : false;
end

#read_double(source) ⇒ Object



12
13
14
# File 'lib/rocketamf/pure/io_helpers.rb', line 12

def read_double source
  source.read(8).unpack('G').first
end

#read_int16_network(source) ⇒ Object



20
21
22
23
24
# File 'lib/rocketamf/pure/io_helpers.rb', line 20

def read_int16_network source
  str = source.read(2)
  str.reverse! if byte_order_little? # swap bytes as native=little (and we want network)
  str.unpack('s').first
end

#read_int8(source) ⇒ Object



4
5
6
# File 'lib/rocketamf/pure/io_helpers.rb', line 4

def read_int8 source
  source.read(1).unpack('c').first
end

#read_word16_network(source) ⇒ Object



16
17
18
# File 'lib/rocketamf/pure/io_helpers.rb', line 16

def read_word16_network source
  source.read(2).unpack('n').first
end

#read_word32_network(source) ⇒ Object



26
27
28
# File 'lib/rocketamf/pure/io_helpers.rb', line 26

def read_word32_network source
  source.read(4).unpack('N').first
end

#read_word8(source) ⇒ Object



8
9
10
# File 'lib/rocketamf/pure/io_helpers.rb', line 8

def read_word8 source
  source.read(1).unpack('C').first
end