mrpin-amf 2.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/README.rdoc +52 -0
  4. data/Rakefile +59 -0
  5. data/benchmark.rb +86 -0
  6. data/doc/amf3-speification.pdf +0 -0
  7. data/ext/rocketamf_ext/class_mapping.c +483 -0
  8. data/ext/rocketamf_ext/constants.h +52 -0
  9. data/ext/rocketamf_ext/deserializer.c +776 -0
  10. data/ext/rocketamf_ext/deserializer.h +28 -0
  11. data/ext/rocketamf_ext/extconf.rb +18 -0
  12. data/ext/rocketamf_ext/remoting.c +184 -0
  13. data/ext/rocketamf_ext/rocketamf_ext.c +38 -0
  14. data/ext/rocketamf_ext/serializer.c +834 -0
  15. data/ext/rocketamf_ext/serializer.h +29 -0
  16. data/ext/rocketamf_ext/utility.h +4 -0
  17. data/lib/amf/common/hash_with_type.rb +20 -0
  18. data/lib/amf/ext.rb +22 -0
  19. data/lib/amf/pure/amf_constants.rb +42 -0
  20. data/lib/amf/pure/deserializer.rb +354 -0
  21. data/lib/amf/pure/errors/all_files.rb +2 -0
  22. data/lib/amf/pure/errors/amf_error.rb +5 -0
  23. data/lib/amf/pure/errors/amf_error_incomplete.rb +5 -0
  24. data/lib/amf/pure/helpers/all_files.rb +8 -0
  25. data/lib/amf/pure/helpers/cache_objects.rb +18 -0
  26. data/lib/amf/pure/helpers/cache_strings.rb +14 -0
  27. data/lib/amf/pure/helpers/io_helper_base.rb +19 -0
  28. data/lib/amf/pure/helpers/io_helper_read.rb +67 -0
  29. data/lib/amf/pure/helpers/io_helper_write.rb +49 -0
  30. data/lib/amf/pure/mapping/class_mapper.rb +159 -0
  31. data/lib/amf/pure/mapping/mapping_set.rb +49 -0
  32. data/lib/amf/pure/serializer.rb +318 -0
  33. data/lib/amf/pure.rb +16 -0
  34. data/lib/amf.rb +140 -0
  35. data/mrpin-amf.gemspec +24 -0
  36. data/spec/fixtures/objects/complex/amf3-associative-array.bin +1 -0
  37. data/spec/fixtures/objects/complex/amf3-byte-array.bin +0 -0
  38. data/spec/fixtures/objects/complex/amf3-date.bin +0 -0
  39. data/spec/fixtures/objects/complex/amf3-dictionary.bin +0 -0
  40. data/spec/fixtures/objects/complex/amf3-dynamic-object.bin +2 -0
  41. data/spec/fixtures/objects/complex/amf3-empty-array.bin +1 -0
  42. data/spec/fixtures/objects/complex/amf3-empty-dictionary.bin +0 -0
  43. data/spec/fixtures/objects/complex/amf3-hash.bin +2 -0
  44. data/spec/fixtures/objects/complex/amf3-mixed-array.bin +10 -0
  45. data/spec/fixtures/objects/complex/amf3-primitive-array.bin +1 -0
  46. data/spec/fixtures/objects/complex/amf3-typed-object.bin +2 -0
  47. data/spec/fixtures/objects/encoding/amf3-complex-encoded-string-array.bin +1 -0
  48. data/spec/fixtures/objects/encoding/amf3-encoded-string-ref.bin +0 -0
  49. data/spec/fixtures/objects/references/amf3-array-ref.bin +1 -0
  50. data/spec/fixtures/objects/references/amf3-byte-array-ref.bin +1 -0
  51. data/spec/fixtures/objects/references/amf3-date-ref.bin +0 -0
  52. data/spec/fixtures/objects/references/amf3-empty-array-ref.bin +1 -0
  53. data/spec/fixtures/objects/references/amf3-empty-string-ref.bin +1 -0
  54. data/spec/fixtures/objects/references/amf3-graph-member.bin +0 -0
  55. data/spec/fixtures/objects/references/amf3-object-ref.bin +0 -0
  56. data/spec/fixtures/objects/references/amf3-string-ref.bin +0 -0
  57. data/spec/fixtures/objects/references/amf3-trait-ref.bin +3 -0
  58. data/spec/fixtures/objects/simple/amf3-0.bin +0 -0
  59. data/spec/fixtures/objects/simple/amf3-bigNum.bin +0 -0
  60. data/spec/fixtures/objects/simple/amf3-false.bin +1 -0
  61. data/spec/fixtures/objects/simple/amf3-float.bin +0 -0
  62. data/spec/fixtures/objects/simple/amf3-large-max.bin +0 -0
  63. data/spec/fixtures/objects/simple/amf3-large-min.bin +0 -0
  64. data/spec/fixtures/objects/simple/amf3-max.bin +1 -0
  65. data/spec/fixtures/objects/simple/amf3-min.bin +0 -0
  66. data/spec/fixtures/objects/simple/amf3-null.bin +1 -0
  67. data/spec/fixtures/objects/simple/amf3-string.bin +1 -0
  68. data/spec/fixtures/objects/simple/amf3-symbol.bin +1 -0
  69. data/spec/fixtures/objects/simple/amf3-true.bin +1 -0
  70. data/spec/helpers/class_mapping_test.rb +4 -0
  71. data/spec/helpers/class_mapping_test2.rb +3 -0
  72. data/spec/helpers/fixtures.rb +34 -0
  73. data/spec/helpers/other_class.rb +4 -0
  74. data/spec/helpers/ruby_class.rb +4 -0
  75. data/spec/helpers/test_ruby_class.rb +4 -0
  76. data/spec/spec-class_mapping.rb +98 -0
  77. data/spec/spec_deserializer.rb +239 -0
  78. data/spec/spec_fast_class_mapping.rb +147 -0
  79. data/spec/spec_helper.rb +8 -0
  80. data/spec/spec_serializer.rb +267 -0
  81. metadata +146 -0
@@ -0,0 +1,267 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper.rb'
4
+ require 'bigdecimal'
5
+ require 'rational'
6
+
7
+ describe 'when serializing' do
8
+ before :each do
9
+ AMF::Root.clear_class_aliases
10
+ end
11
+
12
+
13
+ describe 'AMF3' do
14
+ describe 'simple messages' do
15
+ it 'should serialize a null' do
16
+ compare_with_fixture(nil, 'simple/amf3-null.bin')
17
+ end
18
+
19
+ it 'should serialize a false' do
20
+ compare_with_fixture(false, 'simple/amf3-false.bin')
21
+ end
22
+
23
+ it 'should serialize a true' do
24
+ compare_with_fixture(true, 'simple/amf3-true.bin')
25
+ end
26
+
27
+ it 'should serialize integers' do
28
+ compare_with_fixture(AMF::AMFConstants::INTEGER_MAX, 'simple/amf3-max.bin')
29
+ compare_with_fixture(0, 'simple/amf3-0.bin')
30
+ compare_with_fixture(AMF::AMFConstants::INTEGER_MIN, 'simple/amf3-min.bin')
31
+ end
32
+
33
+ it 'should serialize large integers' do
34
+ compare_with_fixture(AMF::AMFConstants::INTEGER_MAX + 1, 'simple/amf3-large-max.bin')
35
+ compare_with_fixture(AMF::AMFConstants::INTEGER_MIN - 1, 'simple/amf3-large-min.bin')
36
+ end
37
+
38
+ it 'should serialize floats' do
39
+ compare_with_fixture(3.5, 'simple/amf3-float.bin')
40
+ end
41
+
42
+ it 'should serialize BigNums' do
43
+ compare_with_fixture(2**1000, 'simple/amf3-bigNum.bin')
44
+ end
45
+
46
+ it 'should serialize float Numeric conformers' do
47
+ compare_with_fixture(Rational(7, 2), 'simple/amf3-float.bin')
48
+ end
49
+
50
+ it 'should serialize a simple string' do
51
+ compare_with_fixture('String . String', 'simple/amf3-string.bin')
52
+ end
53
+
54
+ it 'should serialize a frozen string' do
55
+ compare_with_fixture('String . String'.freeze, 'simple/amf3-string.bin')
56
+ end
57
+
58
+ it 'should serialize a symbol as a string' do
59
+ compare_with_fixture(:foo, 'simple/amf3-symbol.bin')
60
+ end
61
+ end
62
+
63
+ describe 'objects' do
64
+
65
+ it 'should serialize Date objects' do
66
+ compare_with_fixture(Date.civil(1970, 1, 1, 0), 'complex/amf3-date.bin')
67
+ end
68
+
69
+ it 'should serialize Time objects' do
70
+ compare_with_fixture(Time.utc(1970, 1, 1, 0), 'complex/amf3-date.bin')
71
+ end
72
+
73
+ it 'should serialize DateTime objects' do
74
+ compare_with_fixture(DateTime.civil(1970, 1, 1, 0), 'complex/amf3-date.bin')
75
+ end
76
+
77
+ it 'should serialize an unmapped object as a dynamic anonymous object' do
78
+ class NonMappedObject
79
+ def another_public_property
80
+ 'a_public_value'
81
+ end
82
+
83
+ attr_accessor :nil_property
84
+ attr_accessor :property_one
85
+ attr_writer :read_only_prop
86
+
87
+ def method_with_arg(arg = 'foo')
88
+ arg
89
+ end
90
+ end
91
+ obj = NonMappedObject.new
92
+ obj.property_one = 'foo'
93
+ obj.nil_property = nil
94
+
95
+ compare_with_fixture(obj, 'complex/amf3-dynamic-object.bin')
96
+ end
97
+
98
+ it 'should serialize a hash as a dynamic anonymous object' do
99
+ hash = {}
100
+ hash[:answer] = 42
101
+ hash['foo'] = 'bar'
102
+
103
+ compare_with_fixture(hash, 'complex/amf3-hash.bin')
104
+ end
105
+
106
+ it 'should serialize an empty array' do
107
+ compare_with_fixture([], 'complex/amf3-empty-array.bin')
108
+ end
109
+
110
+ it 'should serialize an array of primitives' do
111
+ compare_with_fixture([1, 2, 3, 4, 5], 'complex/amf3-primitive-array.bin')
112
+ end
113
+
114
+ it 'should serialize an array of mixed objects' do
115
+ value0 = {:foo_one => 'bar_one'}
116
+ value1 = {:foo_two => ''}
117
+ class SimpleObj
118
+ attr_accessor :foo_three
119
+ end
120
+
121
+ value2 = SimpleObj.new
122
+ value2.foo_three = 42
123
+
124
+ input = [value0, value1, value2, {}, [value0, value1, value2], [], 42, '', [], '', {}, 'bar_one', value2]
125
+
126
+ compare_with_fixture(input, 'complex/amf3-mixed-array.bin')
127
+ end
128
+
129
+
130
+ it 'should serialize a byte array' do
131
+ str = "\000\003これtest\100"
132
+ str.force_encoding('ASCII-8BIT') if str.respond_to?(:force_encoding)
133
+ input = StringIO.new(str)
134
+
135
+ compare_with_fixture(input, 'complex/amf3-byte-array.bin')
136
+ end
137
+ end
138
+
139
+ describe 'and implementing the AMF Spec' do
140
+ it 'should keep references of duplicate strings' do
141
+ class StringCarrier
142
+ attr_accessor :str
143
+ end
144
+ foo = 'foo'
145
+ bar = 'str'
146
+
147
+ sc = StringCarrier.new
148
+ sc.str = foo
149
+
150
+ compare_with_fixture([foo, bar, foo, bar, foo, sc], 'references/amf3-string-ref.bin')
151
+ end
152
+
153
+ it 'should not reference the empty string' do
154
+ compare_with_fixture(['', ''], 'references/amf3-empty-string-ref.bin')
155
+ end
156
+
157
+ it 'should keep references of duplicate dates' do
158
+ input = Time.utc 1970, 1, 1, 0
159
+
160
+ compare_with_fixture([input, input], 'references/amf3-date-ref.bin')
161
+ end
162
+
163
+ it 'should keep reference of duplicate objects' do
164
+ class SimpleReferenceableObj
165
+ attr_accessor :foo
166
+ end
167
+ value0 = SimpleReferenceableObj.new
168
+ value0.foo = :bar
169
+
170
+ value1 = SimpleReferenceableObj.new
171
+ value1.foo = value0.foo
172
+
173
+ compare_with_fixture([[value0, value1], 'bar', [value0, value1]], 'references/amf3-object-ref.bin')
174
+
175
+ end
176
+
177
+ it 'should keep reference of duplicate object traits' do
178
+ value0 = RubyClass.new
179
+ value0.foo = 'foo'
180
+
181
+ def value0.encode_amf(serializer)
182
+ serializer.write_object(self, nil, {:class_name => 'org.amf.ASClass', :dynamic => false, :externalizable => false, :members => %w( baz foo )})
183
+ end
184
+
185
+ value1 = RubyClass.new
186
+ value1.foo = 'bar'
187
+
188
+ def value1.encode_amf(serializer)
189
+ serializer.write_object(self, nil, {:class_name => 'org.amf.ASClass', :dynamic => false, :externalizable => false, :members => %w( baz foo )})
190
+ end
191
+
192
+ compare_with_fixture([value0, value1], 'references/amf3-trait-ref.bin')
193
+ end
194
+
195
+ it 'should keep references of duplicate arrays' do
196
+ a = [1, 2, 3]
197
+ b = %w{ a b c }
198
+
199
+ compare_with_fixture([a, b, a, b], 'references/amf3-array-ref.bin')
200
+ end
201
+
202
+ it 'should not keep references of duplicate empty arrays unless the object_id matches' do
203
+ a = []
204
+ b = []
205
+ expect(a).to eq(b)
206
+ expect(a.object_id).not_to eq(b.object_id)
207
+
208
+ compare_with_fixture([a, b, a, b], 'references/amf3-empty-array-ref.bin')
209
+ end
210
+
211
+ it 'should keep references of duplicate byte arrays' do
212
+ value = StringIO.new 'ASDF'
213
+
214
+ compare_with_fixture([value, value], 'references/amf3-byte-array-ref.bin')
215
+ end
216
+
217
+ it 'should serialize a deep object graph with circular references' do
218
+ class GraphMember
219
+ attr_accessor :children
220
+ attr_accessor :parent
221
+
222
+ def initialize
223
+ self.children = []
224
+ end
225
+
226
+ def add_child(child)
227
+ children << child
228
+ child.parent = self
229
+ child
230
+ end
231
+ end
232
+
233
+ input = GraphMember.new
234
+ #level_1_child_1
235
+ input.add_child(GraphMember.new)
236
+ #level_1_child_2
237
+ input.add_child(GraphMember.new)
238
+
239
+ compare_with_fixture(input, 'references/amf3-graph-member.bin')
240
+ end
241
+ end
242
+
243
+ describe 'and handling encodings', if: ''.respond_to?(:force_encoding) do
244
+ it 'should support multiple encodings' do
245
+ shift_str = "\x53\x68\x69\x66\x74\x20\x83\x65\x83\x58\x83\x67".force_encoding('Shift_JIS') # 'Shift テスト'
246
+ utf_str = "\x55\x54\x46\x20\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8') # 'UTF テスト'
247
+
248
+ compare_with_fixture([5, shift_str, utf_str, 5], 'encoding/amf3-complex-encoded-string-array.bin')
249
+ end
250
+
251
+ it 'should keep references of duplicate strings with different encodings' do
252
+ # String is 'this is a テスト'
253
+ shift_str = "\x74\x68\x69\x73\x20\x69\x73\x20\x61\x20\x83\x65\x83\x58\x83\x67".force_encoding('Shift_JIS')
254
+ utf_str = "\x74\x68\x69\x73\x20\x69\x73\x20\x61\x20\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8')
255
+
256
+ compare_with_fixture([shift_str, utf_str], 'encoding/amf3-encoded-string-ref.bin')
257
+ end
258
+
259
+ it 'should handle inappropriate UTF-8 characters in byte arrays' do
260
+ str = "\xff\xff\xff".force_encoding('ASCII-8BIT')
261
+ str.freeze # For added amusement
262
+ output = AMF::Root.serialize(StringIO.new(str))
263
+ expect(output).to eq("\x0c\x07\xff\xff\xff".force_encoding('ASCII-8BIT'))
264
+ end
265
+ end
266
+ end
267
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mrpin-amf
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.8
5
+ platform: ruby
6
+ authors:
7
+ - Jacob Henry
8
+ - Stephen Augenstein
9
+ - Joc O'Connor
10
+ - Gregory Tkach
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2015-11-05 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rake-compiler
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Fast AMF3 serializer/deserializer with remoting request/response wrappers
31
+ to simplify integration
32
+ email:
33
+ - gregory.tkach@gmail.com
34
+ executables: []
35
+ extensions:
36
+ - ext/rocketamf_ext/extconf.rb
37
+ extra_rdoc_files:
38
+ - README.rdoc
39
+ files:
40
+ - .gitignore
41
+ - README.rdoc
42
+ - Rakefile
43
+ - benchmark.rb
44
+ - doc/amf3-speification.pdf
45
+ - ext/rocketamf_ext/class_mapping.c
46
+ - ext/rocketamf_ext/constants.h
47
+ - ext/rocketamf_ext/deserializer.c
48
+ - ext/rocketamf_ext/deserializer.h
49
+ - ext/rocketamf_ext/extconf.rb
50
+ - ext/rocketamf_ext/remoting.c
51
+ - ext/rocketamf_ext/rocketamf_ext.c
52
+ - ext/rocketamf_ext/serializer.c
53
+ - ext/rocketamf_ext/serializer.h
54
+ - ext/rocketamf_ext/utility.h
55
+ - lib/amf.rb
56
+ - lib/amf/common/hash_with_type.rb
57
+ - lib/amf/ext.rb
58
+ - lib/amf/pure.rb
59
+ - lib/amf/pure/amf_constants.rb
60
+ - lib/amf/pure/deserializer.rb
61
+ - lib/amf/pure/errors/all_files.rb
62
+ - lib/amf/pure/errors/amf_error.rb
63
+ - lib/amf/pure/errors/amf_error_incomplete.rb
64
+ - lib/amf/pure/helpers/all_files.rb
65
+ - lib/amf/pure/helpers/cache_objects.rb
66
+ - lib/amf/pure/helpers/cache_strings.rb
67
+ - lib/amf/pure/helpers/io_helper_base.rb
68
+ - lib/amf/pure/helpers/io_helper_read.rb
69
+ - lib/amf/pure/helpers/io_helper_write.rb
70
+ - lib/amf/pure/mapping/class_mapper.rb
71
+ - lib/amf/pure/mapping/mapping_set.rb
72
+ - lib/amf/pure/serializer.rb
73
+ - mrpin-amf.gemspec
74
+ - spec/fixtures/objects/complex/amf3-associative-array.bin
75
+ - spec/fixtures/objects/complex/amf3-byte-array.bin
76
+ - spec/fixtures/objects/complex/amf3-date.bin
77
+ - spec/fixtures/objects/complex/amf3-dictionary.bin
78
+ - spec/fixtures/objects/complex/amf3-dynamic-object.bin
79
+ - spec/fixtures/objects/complex/amf3-empty-array.bin
80
+ - spec/fixtures/objects/complex/amf3-empty-dictionary.bin
81
+ - spec/fixtures/objects/complex/amf3-hash.bin
82
+ - spec/fixtures/objects/complex/amf3-mixed-array.bin
83
+ - spec/fixtures/objects/complex/amf3-primitive-array.bin
84
+ - spec/fixtures/objects/complex/amf3-typed-object.bin
85
+ - spec/fixtures/objects/encoding/amf3-complex-encoded-string-array.bin
86
+ - spec/fixtures/objects/encoding/amf3-encoded-string-ref.bin
87
+ - spec/fixtures/objects/references/amf3-array-ref.bin
88
+ - spec/fixtures/objects/references/amf3-byte-array-ref.bin
89
+ - spec/fixtures/objects/references/amf3-date-ref.bin
90
+ - spec/fixtures/objects/references/amf3-empty-array-ref.bin
91
+ - spec/fixtures/objects/references/amf3-empty-string-ref.bin
92
+ - spec/fixtures/objects/references/amf3-graph-member.bin
93
+ - spec/fixtures/objects/references/amf3-object-ref.bin
94
+ - spec/fixtures/objects/references/amf3-string-ref.bin
95
+ - spec/fixtures/objects/references/amf3-trait-ref.bin
96
+ - spec/fixtures/objects/simple/amf3-0.bin
97
+ - spec/fixtures/objects/simple/amf3-bigNum.bin
98
+ - spec/fixtures/objects/simple/amf3-false.bin
99
+ - spec/fixtures/objects/simple/amf3-float.bin
100
+ - spec/fixtures/objects/simple/amf3-large-max.bin
101
+ - spec/fixtures/objects/simple/amf3-large-min.bin
102
+ - spec/fixtures/objects/simple/amf3-max.bin
103
+ - spec/fixtures/objects/simple/amf3-min.bin
104
+ - spec/fixtures/objects/simple/amf3-null.bin
105
+ - spec/fixtures/objects/simple/amf3-string.bin
106
+ - spec/fixtures/objects/simple/amf3-symbol.bin
107
+ - spec/fixtures/objects/simple/amf3-true.bin
108
+ - spec/helpers/class_mapping_test.rb
109
+ - spec/helpers/class_mapping_test2.rb
110
+ - spec/helpers/fixtures.rb
111
+ - spec/helpers/other_class.rb
112
+ - spec/helpers/ruby_class.rb
113
+ - spec/helpers/test_ruby_class.rb
114
+ - spec/spec-class_mapping.rb
115
+ - spec/spec_deserializer.rb
116
+ - spec/spec_fast_class_mapping.rb
117
+ - spec/spec_helper.rb
118
+ - spec/spec_serializer.rb
119
+ homepage: https://github.com/mrpin/mrpin-amf-ruby
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options:
125
+ - --line-numbers
126
+ - --main
127
+ - README.rdoc
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.4.6
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Fast AMF3 serializer/deserializer
146
+ test_files: []