Class: RocketAMF::Envelope
- Inherits:
-
Object
- Object
- RocketAMF::Envelope
- Includes:
- Pure::Envelope
- Defined in:
- lib/rocketamf/pure.rb,
lib/rocketamf/remoting.rb
Overview
Container for the AMF request/response.
Instance Attribute Summary collapse
-
#amf_version ⇒ Object
readonly
Returns the value of attribute amf_version.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
-
#each_method_call(request, &block) ⇒ Object
Builds response from the request, iterating over each method call and using the return value as the method call’s return value – Iterate over all the sent messages.
-
#initialize(props = {}) ⇒ Envelope
constructor
A new instance of Envelope.
-
#populate_from_stream(stream) ⇒ Object
Populates the envelope from the given stream or string.
-
#serialize ⇒ Object
Serializes the envelope to a string and returns it – Implemented in pure/remoting.rb RocketAMF::Pure::Envelope.
-
#to_s ⇒ Object
Return the serialized envelope as a string.
Methods included from Pure::WriteIOHelpers
#byte_order, #byte_order_little?, #pack_double, #pack_int16_network, #pack_int8, #pack_integer, #pack_word32_network
Methods included from Pure::ReadIOHelpers
#byte_order, #byte_order_little?, #read_double, #read_int16_network, #read_int8, #read_word16_network, #read_word32_network, #read_word8
Constructor Details
#initialize(props = {}) ⇒ Envelope
Returns a new instance of Envelope.
6 7 8 9 10 |
# File 'lib/rocketamf/remoting.rb', line 6 def initialize props={} @amf_version = props[:amf_version] || 0 @headers = props[:headers] || [] @messages = props[:messages] || [] end |
Instance Attribute Details
#amf_version ⇒ Object (readonly)
Returns the value of attribute amf_version.
4 5 6 |
# File 'lib/rocketamf/remoting.rb', line 4 def amf_version @amf_version end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
4 5 6 |
# File 'lib/rocketamf/remoting.rb', line 4 def headers @headers end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
4 5 6 |
# File 'lib/rocketamf/remoting.rb', line 4 def @messages end |
Instance Method Details
#each_method_call(request, &block) ⇒ Object
Builds response from the request, iterating over each method call and using the return value as the method call’s return value – Iterate over all the sent messages. If they’re somthing we can handle, like a command message, then simply add the response message ourselves. If it’s a method call, then call the block with the method and args, catching errors for handling. Then create the appropriate response message using the return value of the block as the return value for the method call.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rocketamf/remoting.rb', line 39 def each_method_call request, &block raise 'Response already constructed' if @constructed # Set version from response # Can't just copy version because FMS sends version as 1 @amf_version = request.amf_version == 3 ? 3 : 0 request..each do |m| # What's the request body? case m.data when Values::CommandMessage # Pings should be responded to with an AcknowledgeMessage built using the ping # Everything else is unsupported command_msg = m.data if command_msg.operation == Values::CommandMessage::CLIENT_PING_OPERATION response_value = Values::AcknowledgeMessage.new(command_msg) else e = Exception.new("CommandMessage #{command_msg.operation} not implemented") e.set_backtrace ["RocketAMF::Envelope each_method_call"] response_value = Values::ErrorMessage.new(command_msg, e) end when Values::RemotingMessage # Using RemoteObject style message calls remoting_msg = m.data acknowledge_msg = Values::AcknowledgeMessage.new(remoting_msg) method_base = remoting_msg.source.to_s.empty? ? '' : remoting_msg.source+'.' body = dispatch_call :method => method_base+remoting_msg.operation, :args => remoting_msg.body, :source => remoting_msg, :block => block # Response should be the bare ErrorMessage if there was an error if body.is_a?(Values::ErrorMessage) response_value = body else acknowledge_msg.body = body response_value = acknowledge_msg end else # Standard response message response_value = dispatch_call :method => m.target_uri, :args => m.data, :source => m, :block => block end target_uri = m.response_uri target_uri += response_value.is_a?(Values::ErrorMessage) ? '/onStatus' : '/onResult' @messages << ::RocketAMF::Message.new(target_uri, '', response_value) end @constructed = true end |
#populate_from_stream(stream) ⇒ Object
20 21 22 |
# File 'lib/rocketamf/remoting.rb', line 20 def populate_from_stream stream raise AMFError, 'Must load "rocketamf/pure"' end |
#serialize ⇒ Object
Serializes the envelope to a string and returns it – Implemented in pure/remoting.rb RocketAMF::Pure::Envelope
27 28 29 |
# File 'lib/rocketamf/remoting.rb', line 27 def serialize raise AMFError, 'Must load "rocketamf/pure"' end |
#to_s ⇒ Object
Return the serialized envelope as a string
88 89 90 |
# File 'lib/rocketamf/remoting.rb', line 88 def to_s serialize end |