Class: EventMachine::RTMP::Message
- Inherits:
-
Object
- Object
- EventMachine::RTMP::Message
- Defined in:
- lib/em-rtmp/message.rb
Class Attribute Summary collapse
-
.transaction_id ⇒ Object
Returns the value of attribute transaction_id.
Instance Attribute Summary collapse
-
#_amf_data ⇒ Object
Returns the value of attribute _amf_data.
-
#_amf_error ⇒ Object
Returns the value of attribute _amf_error.
-
#_amf_unparsed ⇒ Object
Returns the value of attribute _amf_unparsed.
-
#command ⇒ Object
Returns the value of attribute command.
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
-
#values ⇒ Object
Returns the value of attribute values.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #amf3? ⇒ Boolean
- #decode(string) ⇒ Object
-
#encode ⇒ Object
Encode this message with the chosen serializer.
-
#initialize(attrs = {}) ⇒ Message
constructor
Initialize, setting attributes as given.
- #success? ⇒ Boolean
Constructor Details
#initialize(attrs = {}) ⇒ Message
Initialize, setting attributes as given
attrs - Hash of attributes
Returns nothing
17 18 19 20 21 22 23 |
# File 'lib/em-rtmp/message.rb', line 17 def initialize(attrs={}) attrs.each {|k,v| send("#{k}=", v)} self.command ||= nil self.transaction_id ||= self.class.next_transaction_id self.values ||= [] self.version ||= 0x00 end |
Class Attribute Details
.transaction_id ⇒ Object
Returns the value of attribute transaction_id.
6 7 8 |
# File 'lib/em-rtmp/message.rb', line 6 def transaction_id @transaction_id end |
Instance Attribute Details
#_amf_data ⇒ Object
Returns the value of attribute _amf_data.
9 10 11 |
# File 'lib/em-rtmp/message.rb', line 9 def _amf_data @_amf_data end |
#_amf_error ⇒ Object
Returns the value of attribute _amf_error.
9 10 11 |
# File 'lib/em-rtmp/message.rb', line 9 def _amf_error @_amf_error end |
#_amf_unparsed ⇒ Object
Returns the value of attribute _amf_unparsed.
9 10 11 |
# File 'lib/em-rtmp/message.rb', line 9 def _amf_unparsed @_amf_unparsed end |
#command ⇒ Object
Returns the value of attribute command.
10 11 12 |
# File 'lib/em-rtmp/message.rb', line 10 def command @command end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
10 11 12 |
# File 'lib/em-rtmp/message.rb', line 10 def transaction_id @transaction_id end |
#values ⇒ Object
Returns the value of attribute values.
10 11 12 |
# File 'lib/em-rtmp/message.rb', line 10 def values @values end |
#version ⇒ Object
Returns the value of attribute version.
10 11 12 |
# File 'lib/em-rtmp/message.rb', line 10 def version @version end |
Class Method Details
.next_transaction_id ⇒ Object
89 90 91 92 |
# File 'lib/em-rtmp/message.rb', line 89 def self.next_transaction_id self.transaction_id ||= 0 self.transaction_id += 1 end |
Instance Method Details
#amf3? ⇒ Boolean
25 26 27 |
# File 'lib/em-rtmp/message.rb', line 25 def amf3? version == 0x03 end |
#decode(string) ⇒ Object
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 |
# File 'lib/em-rtmp/message.rb', line 57 def decode(string) class_mapper = RocketAMF::ClassMapper.new io = StringIO.new string des = RocketAMF::Deserializer.new class_mapper begin if amf3? byte = des.deserialize 3, io unless byte == nil raise AMFException, "wanted amf3 first byte of 0x00, got #{byte}" end end until io.eof? self.values << des.deserialize(0, io) end rescue => e self._amf_data = string self._amf_error = e self._amf_unparsed = io.read(100_000) end self.command = values.delete_at(0) self.transaction_id = values.delete_at(0) end |
#encode ⇒ Object
Encode this message with the chosen serializer
Returns a string containing an encoded message
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/em-rtmp/message.rb', line 32 def encode Logger.debug "encoding #{self.inspect}" class_mapper = RocketAMF::ClassMapper.new ser = RocketAMF::Serializer.new class_mapper if amf3? ser.stream << "\x00" end ser.serialize 0, command ser.serialize 0, transaction_id if amf3? ser.stream << "\x05" ser.stream << "\x11" ser.serialize 3, values.first else values.each do |value| ser.serialize 0, value end end ser.stream end |
#success? ⇒ Boolean
85 86 87 |
# File 'lib/em-rtmp/message.rb', line 85 def success? (command != "_error") && _amf_error.nil? end |