RocketAMF 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/rocketamf.rb +42 -1
- data/lib/rocketamf/class_mapping.rb +24 -2
- data/lib/rocketamf/pure.rb +5 -3
- data/lib/rocketamf/pure/deserializer.rb +34 -30
- data/lib/rocketamf/pure/serializer.rb +4 -4
- data/lib/rocketamf/remoting.rb +5 -3
- data/lib/rocketamf/values/messages.rb +1 -1
- data/lib/rocketamf/version.rb +1 -1
- data/spec/amf/class_mapping_spec.rb +42 -10
- data/spec/amf/deserializer_spec.rb +14 -1
- data/spec/amf/response_spec.rb +12 -0
- data/spec/fixtures/objects/amf3-traitRef.bin +3 -0
- data/spec/fixtures/request/unsupportedCommandMessage.bin +0 -0
- data/spec/spec_helper.rb +0 -9
- metadata +4 -5
- data/lib/rocketamf/common.rb +0 -35
- data/spec/amf/class_mapping_set_spec.rb +0 -34
data/Rakefile
CHANGED
@@ -23,7 +23,7 @@ end
|
|
23
23
|
|
24
24
|
spec = Gem::Specification.new do |s|
|
25
25
|
s.name = 'RocketAMF'
|
26
|
-
s.version = '0.0.
|
26
|
+
s.version = '0.0.6'
|
27
27
|
s.summary = 'Fast AMF serializer/deserializer and request/response wrappers to simplify remoting implementation'
|
28
28
|
|
29
29
|
s.files = FileList['README.rdoc', 'Rakefile', 'lib/**/*.rb', 'spec/**/*.rb', 'spec/**/*.bin', 'spec/spec.opts']
|
data/lib/rocketamf.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
2
2
|
$:.unshift "#{File.expand_path(File.dirname(__FILE__))}/rocketamf/"
|
3
3
|
|
4
|
-
require 'rocketamf/
|
4
|
+
require 'rocketamf/version'
|
5
|
+
require 'rocketamf/class_mapping'
|
6
|
+
require 'rocketamf/constants'
|
7
|
+
require 'rocketamf/remoting'
|
5
8
|
|
6
9
|
module RocketAMF
|
7
10
|
begin
|
@@ -9,4 +12,42 @@ module RocketAMF
|
|
9
12
|
rescue LoadError
|
10
13
|
require 'rocketamf/pure'
|
11
14
|
end
|
15
|
+
|
16
|
+
# Deserialize the AMF string _source_ of the given AMF version into a Ruby
|
17
|
+
# data structure and return it
|
18
|
+
def self.deserialize source, amf_version = 0
|
19
|
+
if amf_version == 0
|
20
|
+
RocketAMF::Deserializer.new.deserialize(source)
|
21
|
+
elsif amf_version == 3
|
22
|
+
RocketAMF::AMF3Deserializer.new.deserialize(source)
|
23
|
+
else
|
24
|
+
raise AMFError, "unsupported version #{amf_version}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Serialize the given Ruby data structure _obj_ into an AMF stream using the
|
29
|
+
# given AMF version
|
30
|
+
def self.serialize obj, amf_version = 0
|
31
|
+
if amf_version == 0
|
32
|
+
RocketAMF::Serializer.new.serialize(obj)
|
33
|
+
elsif amf_version == 3
|
34
|
+
RocketAMF::AMF3Serializer.new.serialize(obj)
|
35
|
+
else
|
36
|
+
raise AMFError, "unsupported version #{amf_version}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# We use const_missing to define the active ClassMapper at runtime. This way,
|
41
|
+
# heavy modification of class mapping functionality is still possible without
|
42
|
+
# forcing extenders to redefine the constant.
|
43
|
+
def self.const_missing const
|
44
|
+
if const == :ClassMapper
|
45
|
+
RocketAMF.const_set(:ClassMapper, RocketAMF::ClassMapping.new)
|
46
|
+
else
|
47
|
+
super(const)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# The base exception for AMF errors.
|
52
|
+
class AMFError < StandardError; end
|
12
53
|
end
|
@@ -14,7 +14,7 @@ module RocketAMF
|
|
14
14
|
#
|
15
15
|
# RocketAMF::ClassMapper.define do |m|
|
16
16
|
# m.map :as => 'AsClass', :ruby => 'RubyClass'
|
17
|
-
# m.map :as => 'vo.User', :ruby => 'User'
|
17
|
+
# m.map :as => 'vo.User', :ruby => 'Model::User'
|
18
18
|
# end
|
19
19
|
#
|
20
20
|
# == Object Population/Serialization
|
@@ -58,6 +58,23 @@ module RocketAMF
|
|
58
58
|
# end
|
59
59
|
# end
|
60
60
|
# RocketAMF::ClassMapper.object_serializers << CustomSerializer.new
|
61
|
+
#
|
62
|
+
# == Complete Replacement
|
63
|
+
#
|
64
|
+
# In some cases, it may be beneficial to replace the default provider of class
|
65
|
+
# mapping completely. In this case, simply assign an instance of your own class
|
66
|
+
# mapper to <tt>RocketAMF::ClassMapper</tt> after loading RocketAMF. Through
|
67
|
+
# the magic of <tt>const_missing</tt>, <tt>ClassMapper</tt> is only defined after
|
68
|
+
# the first access by default, so you get no annoying warning messages.
|
69
|
+
#
|
70
|
+
# Example:
|
71
|
+
#
|
72
|
+
# require 'rubygems'
|
73
|
+
# require 'rocketamf'
|
74
|
+
#
|
75
|
+
# RocketAMF::ClassMapper = MyCustomClassMapper.new
|
76
|
+
# # No warning about already initialized constant ClassMapper
|
77
|
+
# RocketAMF::ClassMapper.class # MyCustomClassMapper
|
61
78
|
class ClassMapping
|
62
79
|
# Container for all mapped classes
|
63
80
|
class MappingSet
|
@@ -124,8 +141,13 @@ module RocketAMF
|
|
124
141
|
yield mappings
|
125
142
|
end
|
126
143
|
|
144
|
+
# Reset all class mappings except the defaults
|
145
|
+
def reset
|
146
|
+
@mappings = nil
|
147
|
+
end
|
148
|
+
|
127
149
|
# Returns the AS class name for the given ruby object. Will also take a string
|
128
|
-
# containing the ruby class name
|
150
|
+
# containing the ruby class name.
|
129
151
|
def get_as_class_name obj
|
130
152
|
# Get class name
|
131
153
|
if obj.is_a?(String)
|
data/lib/rocketamf/pure.rb
CHANGED
@@ -3,13 +3,14 @@ require 'rocketamf/pure/serializer'
|
|
3
3
|
require 'rocketamf/pure/remoting'
|
4
4
|
|
5
5
|
module RocketAMF
|
6
|
-
# This module holds all the modules/classes that implement AMF's
|
7
|
-
#
|
6
|
+
# This module holds all the modules/classes that implement AMF's functionality
|
7
|
+
# in pure ruby
|
8
8
|
module Pure
|
9
9
|
$DEBUG and warn "Using pure library for RocketAMF."
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
#:stopdoc:
|
13
|
+
# Import deserializer
|
13
14
|
Deserializer = RocketAMF::Pure::Deserializer
|
14
15
|
AMF3Deserializer = RocketAMF::Pure::AMF3Deserializer
|
15
16
|
|
@@ -27,4 +28,5 @@ module RocketAMF
|
|
27
28
|
remove_method :serialize
|
28
29
|
include RocketAMF::Pure::Response
|
29
30
|
end
|
31
|
+
#:startdoc:
|
30
32
|
end
|
@@ -44,6 +44,8 @@ module RocketAMF
|
|
44
44
|
read_typed_object source
|
45
45
|
when AMF0_AMF3_MARKER
|
46
46
|
AMF3Deserializer.new.deserialize(source)
|
47
|
+
else
|
48
|
+
raise AMFError, "Invalid type: #{type}"
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
@@ -139,14 +141,14 @@ module RocketAMF
|
|
139
141
|
def read_typed_object source
|
140
142
|
# Create object to add to ref cache
|
141
143
|
class_name = read_string source
|
142
|
-
obj = ClassMapper.get_ruby_obj class_name
|
144
|
+
obj = RocketAMF::ClassMapper.get_ruby_obj class_name
|
143
145
|
@ref_cache << obj
|
144
146
|
|
145
147
|
# Read object props
|
146
148
|
props = read_object source, false
|
147
149
|
|
148
150
|
# Populate object
|
149
|
-
ClassMapper.populate_ruby_obj obj, props, {}
|
151
|
+
RocketAMF::ClassMapper.populate_ruby_obj obj, props, {}
|
150
152
|
return obj
|
151
153
|
end
|
152
154
|
end
|
@@ -164,32 +166,34 @@ module RocketAMF
|
|
164
166
|
source = StringIO.new(source) unless StringIO === source
|
165
167
|
type = read_int8 source unless type
|
166
168
|
case type
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
169
|
+
when AMF3_UNDEFINED_MARKER
|
170
|
+
nil
|
171
|
+
when AMF3_NULL_MARKER
|
172
|
+
nil
|
173
|
+
when AMF3_FALSE_MARKER
|
174
|
+
false
|
175
|
+
when AMF3_TRUE_MARKER
|
176
|
+
true
|
177
|
+
when AMF3_INTEGER_MARKER
|
178
|
+
read_integer source
|
179
|
+
when AMF3_DOUBLE_MARKER
|
180
|
+
read_number source
|
181
|
+
when AMF3_STRING_MARKER
|
182
|
+
read_string source
|
183
|
+
when AMF3_XML_DOC_MARKER
|
184
|
+
#read_xml_string
|
185
|
+
when AMF3_DATE_MARKER
|
186
|
+
read_date source
|
187
|
+
when AMF3_ARRAY_MARKER
|
188
|
+
read_array source
|
189
|
+
when AMF3_OBJECT_MARKER
|
190
|
+
read_object source
|
191
|
+
when AMF3_XML_MARKER
|
192
|
+
#read_amf3_xml
|
193
|
+
when AMF3_BYTE_ARRAY_MARKER
|
194
|
+
#read_amf3_byte_array
|
195
|
+
else
|
196
|
+
raise AMFError, "Invalid type: #{type}"
|
193
197
|
end
|
194
198
|
end
|
195
199
|
|
@@ -316,7 +320,7 @@ module RocketAMF
|
|
316
320
|
@trait_cache << class_definition
|
317
321
|
end
|
318
322
|
|
319
|
-
obj = ClassMapper.get_ruby_obj class_definition["class_name"]
|
323
|
+
obj = RocketAMF::ClassMapper.get_ruby_obj class_definition["class_name"]
|
320
324
|
@object_cache << obj
|
321
325
|
|
322
326
|
if class_definition['externalizable']
|
@@ -337,7 +341,7 @@ module RocketAMF
|
|
337
341
|
end
|
338
342
|
end
|
339
343
|
|
340
|
-
ClassMapper.populate_ruby_obj obj, props, dynamic_props
|
344
|
+
RocketAMF::ClassMapper.populate_ruby_obj obj, props, dynamic_props
|
341
345
|
end
|
342
346
|
obj
|
343
347
|
end
|
@@ -98,7 +98,7 @@ module RocketAMF
|
|
98
98
|
@ref_cache.add_obj obj
|
99
99
|
|
100
100
|
# Is it a typed object?
|
101
|
-
class_name = ClassMapper.get_as_class_name obj
|
101
|
+
class_name = RocketAMF::ClassMapper.get_as_class_name obj
|
102
102
|
if class_name
|
103
103
|
stream << AMF0_TYPED_OBJECT_MARKER
|
104
104
|
stream << pack_int16_network(class_name.length)
|
@@ -114,7 +114,7 @@ module RocketAMF
|
|
114
114
|
include RocketAMF::Pure::WriteIOHelpers
|
115
115
|
def write_prop_list obj, stream
|
116
116
|
# Write prop list
|
117
|
-
props = ClassMapper.props_for_serialization obj
|
117
|
+
props = RocketAMF::ClassMapper.props_for_serialization obj
|
118
118
|
props.sort.each do |key, value| # Sort keys before writing
|
119
119
|
stream << pack_int16_network(key.length)
|
120
120
|
stream << key
|
@@ -248,7 +248,7 @@ module RocketAMF
|
|
248
248
|
stream << AMF3_DYNAMIC_OBJECT
|
249
249
|
|
250
250
|
# Write class name/anonymous
|
251
|
-
class_name = ClassMapper.get_as_class_name obj
|
251
|
+
class_name = RocketAMF::ClassMapper.get_as_class_name obj
|
252
252
|
if class_name
|
253
253
|
write_utf8_vr class_name, stream
|
254
254
|
else
|
@@ -256,7 +256,7 @@ module RocketAMF
|
|
256
256
|
end
|
257
257
|
|
258
258
|
# Write out properties
|
259
|
-
props = ClassMapper.props_for_serialization obj
|
259
|
+
props = RocketAMF::ClassMapper.props_for_serialization obj
|
260
260
|
props.sort.each do |key, val| # Sort props until Ruby 1.9 becomes common
|
261
261
|
write_utf8_vr key.to_s, stream
|
262
262
|
serialize val, stream
|
data/lib/rocketamf/remoting.rb
CHANGED
@@ -10,7 +10,7 @@ module RocketAMF
|
|
10
10
|
end
|
11
11
|
|
12
12
|
# Populates the request from the given stream or string. Returns self for easy
|
13
|
-
# chaining
|
13
|
+
# chaining.
|
14
14
|
#
|
15
15
|
# Example:
|
16
16
|
#
|
@@ -33,7 +33,7 @@ module RocketAMF
|
|
33
33
|
@messages = []
|
34
34
|
end
|
35
35
|
|
36
|
-
# Serializes the response to a string and returns it
|
36
|
+
# Serializes the response to a string and returns it
|
37
37
|
#--
|
38
38
|
# Implemented in pure/remoting.rb RocketAMF::Pure::Response
|
39
39
|
def serialize
|
@@ -65,7 +65,9 @@ module RocketAMF
|
|
65
65
|
if command_msg.operation == Values::CommandMessage::CLIENT_PING_OPERATION
|
66
66
|
response_value = Values::AcknowledgeMessage.new(command_msg)
|
67
67
|
else
|
68
|
-
|
68
|
+
e = Exception.new("CommandMessage #{command_msg.operation} not implemented")
|
69
|
+
e.set_backtrace ["RocketAMF::Response each_method_call"]
|
70
|
+
response_value = Values::ErrorMessage.new(command_msg, e)
|
69
71
|
end
|
70
72
|
when Values::RemotingMessage
|
71
73
|
# Using RemoteObject style message calls
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module RocketAMF
|
2
2
|
module Values #:nodoc:
|
3
3
|
# Base class for all special AS3 response messages. Maps to
|
4
|
-
# <tt>flex.messaging.messages.AbstractMessage</tt
|
4
|
+
# <tt>flex.messaging.messages.AbstractMessage</tt>.
|
5
5
|
class AbstractMessage
|
6
6
|
attr_accessor :clientId
|
7
7
|
attr_accessor :destination
|
data/lib/rocketamf/version.rb
CHANGED
@@ -16,19 +16,19 @@ describe RocketAMF::ClassMapping do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
describe "class name mapping" do
|
20
|
+
it "should allow resetting of mappings back to defaults" do
|
21
|
+
@mapper.reset
|
22
|
+
@mapper.get_as_class_name('ClassMappingTest').should be_nil
|
23
|
+
@mapper.get_as_class_name('RocketAMF::Values::AcknowledgeMessage').should_not be_nil
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
it "should return AS class name for ruby objects" do
|
27
|
+
@mapper.get_as_class_name(ClassMappingTest.new).should == 'ASClass'
|
28
|
+
@mapper.get_as_class_name('ClassMappingTest').should == 'ASClass'
|
29
|
+
@mapper.get_as_class_name('BadClass').should be_nil
|
27
30
|
end
|
28
|
-
@mapper.get_as_class_name(ClassMappingTest.new).should == 'SecondClass'
|
29
|
-
end
|
30
31
|
|
31
|
-
describe "ruby object generator" do
|
32
32
|
it "should instantiate a ruby class" do
|
33
33
|
@mapper.get_ruby_obj('ASClass').should be_a(ClassMappingTest)
|
34
34
|
end
|
@@ -44,6 +44,38 @@ describe RocketAMF::ClassMapping do
|
|
44
44
|
obj.should be_a(RocketAMF::Values::TypedHash)
|
45
45
|
obj.type.should == 'UnmappedClass'
|
46
46
|
end
|
47
|
+
|
48
|
+
it "should map special classes from AS by default" do
|
49
|
+
as_classes = [
|
50
|
+
'flex.messaging.messages.AcknowledgeMessage',
|
51
|
+
'flex.messaging.messages.CommandMessage',
|
52
|
+
'flex.messaging.messages.RemotingMessage',
|
53
|
+
'flex.messaging.io.ArrayCollection'
|
54
|
+
]
|
55
|
+
|
56
|
+
as_classes.each do |as_class|
|
57
|
+
@mapper.get_ruby_obj(as_class).should_not be_a(RocketAMF::Values::TypedHash)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should map special classes from ruby by default" do
|
62
|
+
ruby_classes = [
|
63
|
+
'RocketAMF::Values::AcknowledgeMessage',
|
64
|
+
'RocketAMF::Values::ErrorMessage',
|
65
|
+
'RocketAMF::Values::ArrayCollection'
|
66
|
+
]
|
67
|
+
|
68
|
+
ruby_classes.each do |obj|
|
69
|
+
@mapper.get_as_class_name(obj).should_not be_nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should allow config modification" do
|
74
|
+
@mapper.define do |m|
|
75
|
+
m.map :as => 'SecondClass', :ruby => 'ClassMappingTest'
|
76
|
+
end
|
77
|
+
@mapper.get_as_class_name(ClassMappingTest.new).should == 'SecondClass'
|
78
|
+
end
|
47
79
|
end
|
48
80
|
|
49
81
|
describe "ruby object populator" do
|
@@ -211,7 +211,7 @@ describe "when deserializing" do
|
|
211
211
|
output.should == []
|
212
212
|
end
|
213
213
|
|
214
|
-
it "should deserialize an array of
|
214
|
+
it "should deserialize an array of primitives" do
|
215
215
|
input = object_fixture("amf3-primArray.bin")
|
216
216
|
output = RocketAMF.deserialize(input, 3)
|
217
217
|
output.should == [1,2,3,4,5]
|
@@ -267,6 +267,19 @@ describe "when deserializing" do
|
|
267
267
|
output.should == [[obj1, obj2], "bar", [obj1, obj2]]
|
268
268
|
end
|
269
269
|
|
270
|
+
it "should keep reference of duplicate object traits" do
|
271
|
+
class RubyClass
|
272
|
+
attr_accessor :foo, :baz
|
273
|
+
end
|
274
|
+
RocketAMF::ClassMapper.define {|m| m.map :as => 'org.rocketAMF.ASClass', :ruby => 'RubyClass'}
|
275
|
+
|
276
|
+
input = object_fixture("amf3-traitRef.bin")
|
277
|
+
output = RocketAMF.deserialize(input, 3)
|
278
|
+
|
279
|
+
output[0].foo.should == "foo"
|
280
|
+
output[1].foo.should == "bar"
|
281
|
+
end
|
282
|
+
|
270
283
|
it "should keep references of duplicate arrays" do
|
271
284
|
input = object_fixture("amf3-arrayRef.bin")
|
272
285
|
output = RocketAMF.deserialize(input, 3)
|
data/spec/amf/response_spec.rb
CHANGED
@@ -40,6 +40,18 @@ describe RocketAMF::Response do
|
|
40
40
|
res.messages[0].data.should be_a(RocketAMF::Values::AcknowledgeMessage)
|
41
41
|
end
|
42
42
|
|
43
|
+
it "should fail on unsupported command" do
|
44
|
+
res = RocketAMF::Response.new
|
45
|
+
req = create_request('unsupportedCommandMessage.bin')
|
46
|
+
res.each_method_call req do |method, args|
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
|
50
|
+
res.messages.length.should == 1
|
51
|
+
res.messages[0].data.should be_a(RocketAMF::Values::ErrorMessage)
|
52
|
+
res.messages[0].data.faultString.should == "CommandMessage 10000 not implemented"
|
53
|
+
end
|
54
|
+
|
43
55
|
it "should handle RemotingMessages properly" do
|
44
56
|
res = RocketAMF::Response.new
|
45
57
|
req = create_request('remotingMessage.bin')
|
Binary file
|
data/spec/spec_helper.rb
CHANGED
@@ -20,13 +20,4 @@ end
|
|
20
20
|
|
21
21
|
def create_request(binary_path)
|
22
22
|
RocketAMF::Request.new.populate_from_stream(StringIO.new(request_fixture(binary_path)))
|
23
|
-
end
|
24
|
-
|
25
|
-
# Add reset support to ClassMapping
|
26
|
-
module RocketAMF
|
27
|
-
class ClassMapping
|
28
|
-
def reset
|
29
|
-
@mappings = nil
|
30
|
-
end
|
31
|
-
end
|
32
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RocketAMF
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Hillerson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2010-01-22 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -26,7 +26,6 @@ files:
|
|
26
26
|
- README.rdoc
|
27
27
|
- Rakefile
|
28
28
|
- lib/rocketamf/class_mapping.rb
|
29
|
-
- lib/rocketamf/common.rb
|
30
29
|
- lib/rocketamf/constants.rb
|
31
30
|
- lib/rocketamf/pure/deserializer.rb
|
32
31
|
- lib/rocketamf/pure/io_helpers.rb
|
@@ -39,7 +38,6 @@ files:
|
|
39
38
|
- lib/rocketamf/values/typed_hash.rb
|
40
39
|
- lib/rocketamf/version.rb
|
41
40
|
- lib/rocketamf.rb
|
42
|
-
- spec/amf/class_mapping_set_spec.rb
|
43
41
|
- spec/amf/class_mapping_spec.rb
|
44
42
|
- spec/amf/deserializer_spec.rb
|
45
43
|
- spec/amf/request_spec.rb
|
@@ -84,6 +82,7 @@ files:
|
|
84
82
|
- spec/fixtures/objects/amf3-string.bin
|
85
83
|
- spec/fixtures/objects/amf3-stringRef.bin
|
86
84
|
- spec/fixtures/objects/amf3-symbol.bin
|
85
|
+
- spec/fixtures/objects/amf3-traitRef.bin
|
87
86
|
- spec/fixtures/objects/amf3-true.bin
|
88
87
|
- spec/fixtures/objects/amf3-typedObject.bin
|
89
88
|
- spec/fixtures/request/acknowledge-response.bin
|
@@ -91,6 +90,7 @@ files:
|
|
91
90
|
- spec/fixtures/request/commandMessage.bin
|
92
91
|
- spec/fixtures/request/remotingMessage.bin
|
93
92
|
- spec/fixtures/request/simple-response.bin
|
93
|
+
- spec/fixtures/request/unsupportedCommandMessage.bin
|
94
94
|
- spec/spec.opts
|
95
95
|
has_rdoc: true
|
96
96
|
homepage: http://github.com/warhammerkid/rocket-amf
|
@@ -123,7 +123,6 @@ signing_key:
|
|
123
123
|
specification_version: 3
|
124
124
|
summary: Fast AMF serializer/deserializer and request/response wrappers to simplify remoting implementation
|
125
125
|
test_files:
|
126
|
-
- spec/amf/class_mapping_set_spec.rb
|
127
126
|
- spec/amf/class_mapping_spec.rb
|
128
127
|
- spec/amf/deserializer_spec.rb
|
129
128
|
- spec/amf/request_spec.rb
|
data/lib/rocketamf/common.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'rocketamf/version'
|
2
|
-
require 'rocketamf/class_mapping'
|
3
|
-
require 'rocketamf/constants'
|
4
|
-
require 'rocketamf/remoting'
|
5
|
-
|
6
|
-
module RocketAMF
|
7
|
-
class << self
|
8
|
-
# Deserialize the AMF string _source_ into a Ruby data structure and return it.
|
9
|
-
def deserialize source, amf_version = 0
|
10
|
-
if amf_version == 0
|
11
|
-
RocketAMF::Deserializer.new.deserialize(source)
|
12
|
-
elsif amf_version == 3
|
13
|
-
RocketAMF::AMF3Deserializer.new.deserialize(source)
|
14
|
-
else
|
15
|
-
raise AMFError, "unsupported version #{amf_version}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Serialize the given Ruby data structure _obj_ into an AMF stream
|
20
|
-
def serialize obj, amf_version = 0
|
21
|
-
if amf_version == 0
|
22
|
-
RocketAMF::Serializer.new.serialize(obj)
|
23
|
-
elsif amf_version == 3
|
24
|
-
RocketAMF::AMF3Serializer.new.serialize(obj)
|
25
|
-
else
|
26
|
-
raise AMFError, "unsupported version #{amf_version}"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
ClassMapper = RocketAMF::ClassMapping.new
|
32
|
-
|
33
|
-
# The base exception for AMF errors.
|
34
|
-
class AMFError < StandardError; end
|
35
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
-
|
3
|
-
describe RocketAMF::ClassMapping::MappingSet do
|
4
|
-
before :each do
|
5
|
-
@config = RocketAMF::ClassMapping::MappingSet.new
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should retrieve AS mapping for ruby class" do
|
9
|
-
@config.map :as => 'ASTest', :ruby => 'RubyTest'
|
10
|
-
@config.get_as_class_name('RubyTest').should == 'ASTest'
|
11
|
-
@config.get_as_class_name('BadClass').should be_nil
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should retrive ruby class name mapping for AS class" do
|
15
|
-
@config.map :as => 'ASTest', :ruby => 'RubyTest'
|
16
|
-
@config.get_ruby_class_name('ASTest').should == 'RubyTest'
|
17
|
-
@config.get_ruby_class_name('BadClass').should be_nil
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should map special classes by default" do
|
21
|
-
SPECIAL_CLASSES = [
|
22
|
-
'flex.messaging.messages.AcknowledgeMessage',
|
23
|
-
'flex.messaging.messages.ErrorMessage',
|
24
|
-
'flex.messaging.messages.CommandMessage',
|
25
|
-
'flex.messaging.messages.ErrorMessage',
|
26
|
-
'flex.messaging.messages.RemotingMessage',
|
27
|
-
'flex.messaging.io.ArrayCollection'
|
28
|
-
]
|
29
|
-
|
30
|
-
SPECIAL_CLASSES.each do |as_class|
|
31
|
-
@config.get_ruby_class_name(as_class).should_not be_nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|