Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'rubygems'
require 'rake'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'rspec/core/rake_task'
require 'rake/extensiontask'
require 'rdoc/task'
require 'rubygems/package_task'
require 'rspec/core/rake_task'

desc 'Default: run the specs.'
task :default => :spec
Expand Down Expand Up @@ -33,7 +33,7 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include("lib") # Don't include ext folder because no one cares
end

Rake::GemPackageTask.new(spec) do |pkg|
Gem::PackageTask.new(spec) do |pkg|
pkg.need_zip = false
pkg.need_tar = false
end
Expand Down
10 changes: 10 additions & 0 deletions ext/rocketamf_ext/serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,16 @@ static VALUE ser3_serialize(VALUE self, VALUE obj) {
klass = CLASS_OF(obj);
}

//Detects proxy arrays and converts them to real arrays
if(type == T_OBJECT){
VALUE testObj = rb_check_array_type(obj);
if(testObj != Qnil){
obj = testObj;
type = T_ARRAY;
//TODO: clean up old object or will GC take care of it well enough?
}
}

if(rb_respond_to(obj, id_encode_amf)) {
rb_funcall(obj, id_encode_amf, 1, self);
} else if(type == T_STRING || type == T_SYMBOL) {
Expand Down
18 changes: 18 additions & 0 deletions spec/serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@
output.should == object_fixture('amf0-strict-array.bin')
end

it "should serialize an array through a proxy class" do
expected = object_fixture("amf3-primitive-array.bin")
arr = ProxyArray.new
[1,2,3,4,5].each {|e| arr.push e}

output = RocketAMF.serialize(arr,3)
output.should == expected
end

it "should serialize references" do
obj = OtherClass.new
obj.foo = "baz"
Expand Down Expand Up @@ -343,6 +352,15 @@ def obj2.encode_amf serializer
output.should == expected
end

it "should serialize an array through a proxy class" do
expected = object_fixture("amf3-primitive-array.bin")
arr = ProxyArray.new
[1,2,3,4,5].each {|e| arr.push e}

output = RocketAMF.serialize(arr,3)
output.should == expected
end

it "should serialize a byte array" do
expected = object_fixture("amf3-byte-array.bin")
str = "\000\003これtest\100"
Expand Down
11 changes: 11 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ class ClassMappingTest2 < ClassMappingTest
attr_accessor :prop_c
end
module ANamespace; class TestRubyClass; end; end
class ProxyArray
instance_methods.each {|m| undef_method m unless m=~ /^__|^send$|^object_id$/}
protected
def method_missing(name, *args, &block)
target.send(name, *args, &block)
end

def target
@target ||= []
end
end
class ExternalizableTest
include RocketAMF::Pure::ReadIOHelpers
include RocketAMF::Pure::WriteIOHelpers
Expand Down