Class: AMF::Pure::Request

Inherits:
Object
  • Object
show all
Includes:
ReadIOHelpers
Defined in:
lib/amf/pure/remoting.rb

Overview

AMF request object wrapper, it is responsible for deserializing AMF requests

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ReadIOHelpers

#byte_order, #byte_order_little?, #read_double, #read_int16_network, #read_int8, #read_word16_network, #read_word32_network, #read_word8

Constructor Details

#initializeRequest

Returns a new instance of Request.



9
10
11
12
13
# File 'lib/amf/pure/remoting.rb', line 9

def initialize
  @amf_version = 0
  @headers = []
  @messages = []
end

Instance Attribute Details

#amf_versionObject (readonly)

Returns the value of attribute amf_version.



7
8
9
# File 'lib/amf/pure/remoting.rb', line 7

def amf_version
  @amf_version
end

#headersObject (readonly)

Returns the value of attribute headers.



7
8
9
# File 'lib/amf/pure/remoting.rb', line 7

def headers
  @headers
end

#messagesObject (readonly)

Returns the value of attribute messages.



7
8
9
# File 'lib/amf/pure/remoting.rb', line 7

def messages
  @messages
end

Instance Method Details

#populate_from_stream(stream) ⇒ Object



15
16
17
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
43
44
45
# File 'lib/amf/pure/remoting.rb', line 15

def populate_from_stream stream
  stream = StringIO.new(stream) unless StringIO === stream

  # Read AMF version
  @amf_version = read_word16_network stream

  # Read in headers
  header_count = read_word16_network stream
  0.upto(header_count-1) do
    name = stream.read(read_word16_network(stream))
    must_understand = read_int8(stream) != 0
    length = read_word32_network stream
    data = AMF.deserialize stream
    @headers << Header.new(name, must_understand, data)
  end

  # Read in messages
  message_count = read_word16_network stream
  0.upto(message_count-1) do
    target_uri = stream.read(read_word16_network(stream))
    response_uri = stream.read(read_word16_network(stream))
    length = read_word32_network stream
    data = AMF.deserialize stream
    if data.is_a?(Array) && data.length == 1 && data[0].is_a?(::AMF::Values::AbstractMessage)
      data = data[0]
    end
    @messages << Message.new(target_uri, response_uri, data)
  end

  self
end