Permalink
Browse files

Fixed handling of object end. Added support for references.

  • Loading branch information...
1 parent 8b2a287 commit d0428b80fcd35acdd9dca98962e0927fcb202859 @threedaymonk committed Aug 3, 2010
Showing with 12 additions and 2 deletions.
  1. +11 −1 lib/net/rtmp/amf.rb
  2. +1 −1 test/amf/test_parse_amf3.rb
View
@@ -30,6 +30,7 @@ class AMF
def initialize(version=0)
@elements = []
+ @references = []
end
def parse(data)
@@ -80,6 +81,8 @@ def read_object(bytestream)
until (key = read_length_prefixed_data(bytestream)) == ''
hash[key] = next_element(bytestream)
end
+ bytestream.read_uint8 # TODO check it's 0x09
+ @references << hash
hash
end
@@ -102,15 +105,22 @@ def read_object_end(_)
end
def read_strict_array(bytestream)
- (0...bytestream.read_uint32_be).map{
+ array = (0...bytestream.read_uint32_be).map{
next_element(bytestream)
}
+ @references << array
+ array
end
def read_ecma_array(bytestream)
count = bytestream.read_uint32_be
read_object(bytestream)
end
+
+ def read_reference(bytestream)
+ index = bytestream.read_uint16_be
+ @references[index - 1] # 1-indexed
+ end
end
end
end
@@ -1,7 +1,7 @@
require File.expand_path("../../common", __FILE__)
require 'net/rtmp/amf'
-class AMF0ParseTest < Test::Unit::TestCase
+class AMF3ParseTest < Test::Unit::TestCase
def assert_parsed(expected, filename)
path = File.expand_path("../data/amf3/#{filename}", __FILE__)

0 comments on commit d0428b8

Please sign in to comment.