Module: RocketAMF::Pure::IOHelperRead

Includes:
IOHelperBase
Included in:
Deserializer
Defined in:
lib/rocketamf/pure/helpers/io_helper_read.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from IOHelperBase

#byte_order, #byte_order_little?

Instance Method Details

#read_double(source) ⇒ Object

Raises:



28
29
30
31
32
33
34
# File 'lib/rocketamf/pure/helpers/io_helper_read.rb', line 28

def read_double(source)
  bytes_to_read = 8

  raise AMFErrorIncomplete.new if bytes_to_read > (source.size - source.pos)

  source.read(bytes_to_read).unpack('G').first
end

#read_int16_network(source) ⇒ Object

Raises:



46
47
48
49
50
51
52
53
54
# File 'lib/rocketamf/pure/helpers/io_helper_read.rb', line 46

def read_int16_network(source)
  bytes_to_read = 2

  raise AMFErrorIncomplete.new if bytes_to_read > (source.size - source.pos)

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

#read_int8(source) ⇒ Object

Raises:



14
15
16
17
18
# File 'lib/rocketamf/pure/helpers/io_helper_read.rb', line 14

def read_int8(source)
  raise AMFErrorIncomplete.new if source.eof?

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

#read_word16_network(source) ⇒ Object

Raises:



37
38
39
40
41
42
43
# File 'lib/rocketamf/pure/helpers/io_helper_read.rb', line 37

def read_word16_network(source)
  bytes_to_read = 2

  raise AMFErrorIncomplete.new if bytes_to_read > (source.size - source.pos)

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

#read_word32_network(source) ⇒ Object

Raises:



57
58
59
60
61
62
63
# File 'lib/rocketamf/pure/helpers/io_helper_read.rb', line 57

def read_word32_network(source)
  bytes_to_read = 4

  raise AMFErrorIncomplete.new if bytes_to_read > (source.size - source.pos)

  source.read(bytes_to_read).unpack('N').first
end

#read_word8(source) ⇒ Object

Raises:



21
22
23
24
25
# File 'lib/rocketamf/pure/helpers/io_helper_read.rb', line 21

def read_word8(source)
  raise AMFErrorIncomplete.new if source.eof?

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