RocketAMF 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,13 +8,49 @@ A fast AMF serializer/deserializer and request/response wrappers to simplify rem
8
8
 
9
9
  == EXAMPLE:
10
10
 
11
- NEED TO WRITE SOMETHING HERE
11
+ # helloworld.ru
12
+
13
+ require 'rocketamf'
14
+
15
+ class HelloWorldApp
16
+ APPLICATION_AMF = 'application/x-amf'.freeze
17
+
18
+ def call env
19
+ if is_amf?(env)
20
+ # Wrap request and response
21
+ env['rack.input'].rewind
22
+ request = RocketAMF::Request.new.populate_from_stream(env['rack.input'].read)
23
+ response = RocketAMF::Response.new
24
+
25
+ # Handle request
26
+ response.each_method_call request do |method, args|
27
+ raise "Service #{method} does not exists" unless method == 'App.helloWorld'
28
+ 'Hello world'
29
+ end
30
+
31
+ # Pass back response
32
+ response_str = response.serialize
33
+ return [200, {'Content-Type' => APPLICATION_AMF, 'Content-Length' => response_str.length.to_s}, [response_str]]
34
+ else
35
+ return [200, {'Content-Type' => 'text/plain', 'Content-Length' => '16' }, ["Rack AMF gateway"]]
36
+ end
37
+ end
38
+
39
+ private
40
+ def is_amf? env
41
+ return false unless env['CONTENT_TYPE'] == APPLICATION_AMF
42
+ return false unless env['PATH_INFO'] == '/amf'
43
+ return true
44
+ end
45
+ end
46
+
47
+ run HelloWorldApp.new
12
48
 
13
49
  == LICENSE:
14
50
 
15
51
  (The MIT License)
16
52
 
17
- Copyright (c) 2009 Tony Hillerson based on work by Aaron Smith
53
+ Copyright (c) 2009 Stephen Augenstein and Jacob Smith
18
54
 
19
55
  Permission is hereby granted, free of charge, to any person obtaining
20
56
  a copy of this software and associated documentation files (the
@@ -33,4 +69,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33
69
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
34
70
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
35
71
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
36
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
72
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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.6'
26
+ s.version = '0.0.7'
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']
@@ -191,7 +191,7 @@ module RocketAMF
191
191
  when AMF3_XML_MARKER
192
192
  #read_amf3_xml
193
193
  when AMF3_BYTE_ARRAY_MARKER
194
- #read_amf3_byte_array
194
+ read_amf3_byte_array source
195
195
  else
196
196
  raise AMFError, "Invalid type: #{type}"
197
197
  end
@@ -242,11 +242,7 @@ module RocketAMF
242
242
  return @string_cache[reference]
243
243
  else
244
244
  length = type >> 1
245
- #HACK needed for ['',''] array of empty strings
246
- #It may be better to take one more parameter that
247
- #would specify whether or not they expect us to return
248
- #a string
249
- str = "" #if stringRequest
245
+ str = ""
250
246
  if length > 0
251
247
  str = source.read(length)
252
248
  @string_cache << str
@@ -255,6 +251,21 @@ module RocketAMF
255
251
  end
256
252
  end
257
253
 
254
+ def read_amf3_byte_array source
255
+ type = read_integer source
256
+ isReference = (type & 0x01) == 0
257
+
258
+ if isReference
259
+ reference = type >> 1
260
+ return @object_cache[reference]
261
+ else
262
+ length = type >> 1
263
+ obj = StringIO.new source.read(length)
264
+ @object_cache << obj
265
+ obj
266
+ end
267
+ end
268
+
258
269
  def read_array source
259
270
  type = read_integer source
260
271
  isReference = (type & 0x01) == 0
@@ -157,6 +157,8 @@ module RocketAMF
157
157
  write_string obj.to_s, stream
158
158
  elsif obj.is_a?(Time)
159
159
  write_date obj, stream
160
+ elsif obj.is_a?(StringIO)
161
+ write_byte_array obj, stream
160
162
  elsif obj.is_a?(Array)
161
163
  write_array obj, stream
162
164
  elsif obj.is_a?(Hash) || obj.is_a?(Object)
@@ -217,6 +219,16 @@ module RocketAMF
217
219
  end
218
220
  end
219
221
 
222
+ def write_byte_array array, stream
223
+ stream << AMF3_BYTE_ARRAY_MARKER
224
+ if @object_cache[array] != nil
225
+ write_reference @object_cache[array], stream
226
+ else
227
+ @object_cache.add_obj array
228
+ write_utf8_vr array.string, stream
229
+ end
230
+ end
231
+
220
232
  def write_array array, stream
221
233
  stream << AMF3_ARRAY_MARKER
222
234
  if @object_cache[array] != nil
@@ -1,6 +1,6 @@
1
1
  module RocketAMF
2
2
  # AMF version
3
- VERSION = '0.0.6'
3
+ VERSION = '0.0.7'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -168,7 +168,7 @@ describe "when deserializing" do
168
168
  end
169
169
 
170
170
  #BAH! Who sends XML over AMF?
171
- it "should deserialize a REXML document"
171
+ it "should deserialize XML"
172
172
  end
173
173
 
174
174
  describe "objects" do
@@ -227,7 +227,13 @@ describe "when deserializing" do
227
227
  output.should == [h1, h2, so1, {:foo_three => nil}, {}, [h1, h2, so1], [], 42, "", [], "", {}, "bar_one", so1]
228
228
  end
229
229
 
230
- it "should deserialize a byte array"
230
+ it "should deserialize a byte array" do
231
+ input = object_fixture("amf3-byteArray.bin")
232
+ output = RocketAMF.deserialize(input, 3)
233
+
234
+ output.should be_a StringIO
235
+ output.string.should == "\000\003これtest\100"
236
+ end
231
237
  end
232
238
 
233
239
  describe "and implementing the AMF Spec" do
@@ -299,7 +305,13 @@ describe "when deserializing" do
299
305
  end
300
306
 
301
307
  it "should keep references of duplicate XML and XMLDocuments"
302
- it "should keep references of duplicate byte arrays"
308
+
309
+ it "should keep references of duplicate byte arrays" do
310
+ input = object_fixture("amf3-byteArrayRef.bin")
311
+ output = RocketAMF.deserialize(input, 3)
312
+ output[0].object_id.should == output[1].object_id
313
+ output[0].string.should == "ASDF"
314
+ end
303
315
 
304
316
  it "should deserialize a deep object graph with circular references" do
305
317
  input = object_fixture("amf3-graphMember.bin")
@@ -155,7 +155,7 @@ describe "when serializing" do
155
155
  end
156
156
 
157
157
  #BAH! Who sends XML over AMF?
158
- it "should serialize a REXML document"
158
+ it "should serialize XML"
159
159
  end
160
160
 
161
161
  describe "objects" do
@@ -225,7 +225,12 @@ describe "when serializing" do
225
225
  output.should == expected
226
226
  end
227
227
 
228
- it "should serialize a byte array"
228
+ it "should serialize a byte array" do
229
+ expected = object_fixture("amf3-byteArray.bin")
230
+ input = StringIO.new "\000\003これtest\100"
231
+ output = RocketAMF.serialize(input, 3)
232
+ output.should == expected
233
+ end
229
234
  end
230
235
 
231
236
  describe "and implementing the AMF Spec" do
@@ -296,7 +301,15 @@ describe "when serializing" do
296
301
  end
297
302
 
298
303
  it "should keep references of duplicate XML and XMLDocuments"
299
- it "should keep references of duplicate byte arrays"
304
+
305
+ it "should keep references of duplicate byte arrays" do
306
+ b = StringIO.new "ASDF"
307
+
308
+ expected = object_fixture("amf3-byteArrayRef.bin")
309
+ input = [b, b]
310
+ output = RocketAMF.serialize(input, 3)
311
+ output.should == expected
312
+ end
300
313
 
301
314
  it "should serialize a deep object graph with circular references" do
302
315
  class GraphMember
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.6
4
+ version: 0.0.7
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: 2010-01-22 00:00:00 -05:00
13
+ date: 2010-03-30 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -62,6 +62,8 @@ files:
62
62
  - spec/fixtures/objects/amf3-0.bin
63
63
  - spec/fixtures/objects/amf3-arrayRef.bin
64
64
  - spec/fixtures/objects/amf3-bigNum.bin
65
+ - spec/fixtures/objects/amf3-byteArray.bin
66
+ - spec/fixtures/objects/amf3-byteArrayRef.bin
65
67
  - spec/fixtures/objects/amf3-date.bin
66
68
  - spec/fixtures/objects/amf3-datesRef.bin
67
69
  - spec/fixtures/objects/amf3-dynObject.bin