hessian2 2.0.5 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -10
  3. data/README.md +203 -199
  4. data/lib/hessian2.rb +14 -14
  5. data/lib/hessian2/client.rb +57 -57
  6. data/lib/hessian2/constants.rb +164 -164
  7. data/lib/hessian2/fault.rb +3 -3
  8. data/lib/hessian2/handler.rb +18 -18
  9. data/lib/hessian2/hessian_client.rb +3 -3
  10. data/lib/hessian2/parser.rb +619 -619
  11. data/lib/hessian2/type_wrapper.rb +49 -49
  12. data/lib/hessian2/version.rb +3 -3
  13. data/lib/hessian2/writer.rb +506 -504
  14. data/spec/binary_spec.rb +51 -51
  15. data/spec/boolean_spec.rb +26 -26
  16. data/spec/class_wrapper_spec.rb +52 -52
  17. data/spec/create_monkeys.rb +14 -14
  18. data/spec/date_spec.rb +45 -45
  19. data/spec/double_spec.rb +78 -78
  20. data/spec/int_spec.rb +54 -54
  21. data/spec/list_spec.rb +66 -66
  22. data/spec/long_spec.rb +68 -68
  23. data/spec/map_spec.rb +36 -36
  24. data/spec/null_spec.rb +17 -17
  25. data/spec/object_spec.rb +78 -78
  26. data/spec/ref_spec.rb +43 -43
  27. data/spec/spec_helper.rb +23 -23
  28. data/spec/string_spec.rb +61 -61
  29. data/spec/struct_wrapper_spec.rb +47 -47
  30. data/spec/type_wrapper_spec.rb +102 -102
  31. data/test/app.rb +24 -24
  32. data/test/async/em_http_asleep.rb +25 -25
  33. data/test/async/em_http_sleep.rb +25 -25
  34. data/test/async/monkey.asleep.rb +27 -27
  35. data/test/async/mysql2_aquery.rb +37 -37
  36. data/test/fault/monkey.undefined_method.rb +5 -5
  37. data/test/fault/monkey.wrong_arguments.rb +5 -5
  38. data/test/fiber_concurrency/em_http_asleep.rb +17 -17
  39. data/test/fiber_concurrency/em_http_sleep.rb +17 -17
  40. data/test/fiber_concurrency/monkey.asleep.fiber_aware.rb +18 -18
  41. data/test/fiber_concurrency/mysql2_query.rb +29 -29
  42. data/test/fiber_concurrency/net_http_asleep.rb +19 -19
  43. data/test/fiber_concurrency/net_http_sleep.rb +19 -19
  44. data/test/fibered_rainbows/Gemfile +15 -15
  45. data/test/fibered_rainbows/config.ru +11 -11
  46. data/test/fibered_rainbows/rainbows.rb +13 -13
  47. data/test/monkey_service.rb +16 -16
  48. data/test/prepare.rb +7 -7
  49. data/test/thread_concurrency/active_record_execute.rb +29 -29
  50. data/test/thread_concurrency/monkey.asleep.rb +22 -22
  51. data/test/thread_concurrency/net_http_asleep.rb +24 -24
  52. data/test/thread_concurrency/net_http_sleep.rb +24 -24
  53. data/test/threaded_rainbows/Gemfile +13 -13
  54. data/test/threaded_rainbows/config.ru +9 -9
  55. data/test/threaded_rainbows/rainbows.rb +13 -13
  56. metadata +46 -4
@@ -1,54 +1,54 @@
1
- require File.expand_path('../spec_helper', __FILE__)
2
-
3
- module Hessian2
4
- describe Writer do
5
- context "when int" do
6
-
7
- it "should write one-octet compact int (-x10 to x2f, x90 is 0) ::= [x80-xbf]" do
8
- (-0x10..0x2f).each do |val|
9
- bin = Hessian2.write(val)
10
-
11
- expect(bin.unpack('C').first - 0x90).to eq(val)
12
- expect(Hessian2.parse(bin)).to eq(val)
13
- end
14
- end
15
-
16
-
17
- it "should write two-octet compact int (-x800 to x7ff) ::= [xc0-xcf] b0" do
18
- -0x800.step(0x7ff, 0x100).select{|x| !(-0x10..0x2f).include?(x)}.each do |val|
19
- bin = Hessian2.write(val)
20
-
21
- b1, b0 = bin[0, 2].unpack('CC')
22
- expect(((b1 - 0xc8) << 8) + b0).to eq(val)
23
- expect(Hessian2.parse(bin)).to eq(val)
24
- end
25
- end
26
-
27
-
28
- it "should write three-octet compact int (-x40000 to x3ffff) ::= [xd0-xd7] b1 b0" do
29
- -0x40000.step(0x3ffff, 0x10000).select{|x| !(-0x800..0x7ff).include?(x)}.each do |val|
30
- bin = Hessian2.write(val)
31
-
32
- b2, b1, b0 = bin[0, 3].unpack('CCC')
33
- expect(((b2 - 0xd4) << 16) + (b1 << 8) + b0).to eq(val)
34
- expect(Hessian2.parse(bin)).to eq(val)
35
- end
36
- end
37
-
38
-
39
- it "should write 32-bit signed integer ('I') ::= 'I' b3 b2 b1 b0" do
40
- fixnum_max = 2 ** (0.size * 8 - 2) - 1
41
- fixnum_min = -(2 ** (0.size * 8 - 2))
42
-
43
- [ -0x80_000_000, 0x7f_fff_fff, -0x40001, 0x40000 ].each do |val|
44
- bin = Hessian2.write(val > fixnum_max || val < fixnum_min ? Hessian2::TypeWrapper.new(:int, val) : val)
45
-
46
- expect(bin[0]).to eq('I')
47
- expect(bin[1, 4].unpack('l>').first).to eq(val)
48
- expect(Hessian2.parse(bin)).to eq(val)
49
- end
50
- end
51
-
52
- end
53
- end
54
- end
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Hessian2
4
+ describe Writer do
5
+ context "when int" do
6
+
7
+ it "should write one-octet compact int (-x10 to x2f, x90 is 0) ::= [x80-xbf]" do
8
+ (-0x10..0x2f).each do |val|
9
+ bin = Hessian2.write(val)
10
+
11
+ expect(bin.unpack('C').first - 0x90).to eq(val)
12
+ expect(Hessian2.parse(bin)).to eq(val)
13
+ end
14
+ end
15
+
16
+
17
+ it "should write two-octet compact int (-x800 to x7ff) ::= [xc0-xcf] b0" do
18
+ -0x800.step(0x7ff, 0x100).select{|x| !(-0x10..0x2f).include?(x)}.each do |val|
19
+ bin = Hessian2.write(val)
20
+
21
+ b1, b0 = bin[0, 2].unpack('CC')
22
+ expect(((b1 - 0xc8) << 8) + b0).to eq(val)
23
+ expect(Hessian2.parse(bin)).to eq(val)
24
+ end
25
+ end
26
+
27
+
28
+ it "should write three-octet compact int (-x40000 to x3ffff) ::= [xd0-xd7] b1 b0" do
29
+ -0x40000.step(0x3ffff, 0x10000).select{|x| !(-0x800..0x7ff).include?(x)}.each do |val|
30
+ bin = Hessian2.write(val)
31
+
32
+ b2, b1, b0 = bin[0, 3].unpack('CCC')
33
+ expect(((b2 - 0xd4) << 16) + (b1 << 8) + b0).to eq(val)
34
+ expect(Hessian2.parse(bin)).to eq(val)
35
+ end
36
+ end
37
+
38
+
39
+ it "should write 32-bit signed integer ('I') ::= 'I' b3 b2 b1 b0" do
40
+ fixnum_max = 2 ** (0.size * 8 - 2) - 1
41
+ fixnum_min = -(2 ** (0.size * 8 - 2))
42
+
43
+ [ -0x80_000_000, 0x7f_fff_fff, -0x40001, 0x40000 ].each do |val|
44
+ bin = Hessian2.write(val > fixnum_max || val < fixnum_min ? Hessian2::TypeWrapper.new(:int, val) : val)
45
+
46
+ expect(bin[0]).to eq('I')
47
+ expect(bin[1, 4].unpack('l>').first).to eq(val)
48
+ expect(Hessian2.parse(bin)).to eq(val)
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -1,66 +1,66 @@
1
- require File.expand_path('../spec_helper', __FILE__)
2
-
3
- module Hessian2
4
- describe Writer do
5
- context "when list" do
6
-
7
- it "should write variable-length list/vector ('U') ::= x55 type value* 'Z'" do
8
- # not implemented
9
- end
10
-
11
-
12
- it "should write fixed-length list/vector ('V') ::= 'V' type int value*" do
13
- val = (1..9).to_a
14
- bin = Hessian2.write(Hessian2::TypeWrapper.new('[int', val))
15
-
16
- bytes = bin.each_byte
17
- expect([ bytes.next ].pack('C')).to eq('V')
18
- expect(Hessian2.parse_string(bytes)).to eq('[I')
19
- expect(Hessian2.parse_int(bytes)).to eq(val.size)
20
- expect(Hessian2.parse(bin)).to eq(val)
21
- end
22
-
23
-
24
- it "should write variable-length untyped list/vector ('W') ::= x57 value* 'Z'" do
25
- # not implemented
26
- end
27
-
28
-
29
- it "should write fixed-length untyped list/vector ('X') ::= x58 int value*" do
30
- val = [ Time.new(2005, 3, 4), '阿门', 59.59 ] * 3
31
- bin = Hessian2.write(val)
32
-
33
- bytes = bin.each_byte
34
- expect([ bytes.next ].pack('C')).to eq('X')
35
- expect(Hessian2.parse_int(bytes)).to eq(val.size)
36
- expect(Hessian2.parse(bin)).to eq(val)
37
- end
38
-
39
-
40
- it "should write fixed list with direct length ::= [x70-77] type value*" do
41
- 8.times do |i|
42
- val = (0...i).to_a
43
- bin = Hessian2.write(Hessian2::TypeWrapper.new('[int', val))
44
-
45
- bytes = bin.each_byte
46
- expect(bytes.next - 0x70).to eq(val.size)
47
- expect(Hessian2.parse_string(bytes)).to eq('[I')
48
- expect(Hessian2.parse(bin)).to eq(val)
49
- end
50
- end
51
-
52
-
53
- it "should write fixed untyped list with direct length ::= [x78-7f] value*" do
54
- 8.times do |i|
55
- val = (0...i).to_a
56
- bin = Hessian2.write(val)
57
-
58
- bytes = bin.each_byte
59
- expect(bytes.next - 0x78).to eq(val.size)
60
- expect(Hessian2.parse(bin)).to eq(val)
61
- end
62
- end
63
-
64
- end
65
- end
66
- end
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Hessian2
4
+ describe Writer do
5
+ context "when list" do
6
+
7
+ it "should write variable-length list/vector ('U') ::= x55 type value* 'Z'" do
8
+ # not implemented
9
+ end
10
+
11
+
12
+ it "should write fixed-length list/vector ('V') ::= 'V' type int value*" do
13
+ val = (1..9).to_a
14
+ bin = Hessian2.write(Hessian2::TypeWrapper.new('[int', val))
15
+
16
+ bytes = bin.each_byte
17
+ expect([ bytes.next ].pack('C')).to eq('V')
18
+ expect(Hessian2.parse_string(bytes)).to eq('[I')
19
+ expect(Hessian2.parse_int(bytes)).to eq(val.size)
20
+ expect(Hessian2.parse(bin)).to eq(val)
21
+ end
22
+
23
+
24
+ it "should write variable-length untyped list/vector ('W') ::= x57 value* 'Z'" do
25
+ # not implemented
26
+ end
27
+
28
+
29
+ it "should write fixed-length untyped list/vector ('X') ::= x58 int value*" do
30
+ val = [ Time.new(2005, 3, 4), '阿门', 59.59 ] * 3
31
+ bin = Hessian2.write(val)
32
+
33
+ bytes = bin.each_byte
34
+ expect([ bytes.next ].pack('C')).to eq('X')
35
+ expect(Hessian2.parse_int(bytes)).to eq(val.size)
36
+ expect(Hessian2.parse(bin)).to eq(val)
37
+ end
38
+
39
+
40
+ it "should write fixed list with direct length ::= [x70-77] type value*" do
41
+ 8.times do |i|
42
+ val = (0...i).to_a
43
+ bin = Hessian2.write(Hessian2::TypeWrapper.new('[int', val))
44
+
45
+ bytes = bin.each_byte
46
+ expect(bytes.next - 0x70).to eq(val.size)
47
+ expect(Hessian2.parse_string(bytes)).to eq('[I')
48
+ expect(Hessian2.parse(bin)).to eq(val)
49
+ end
50
+ end
51
+
52
+
53
+ it "should write fixed untyped list with direct length ::= [x78-7f] value*" do
54
+ 8.times do |i|
55
+ val = (0...i).to_a
56
+ bin = Hessian2.write(val)
57
+
58
+ bytes = bin.each_byte
59
+ expect(bytes.next - 0x78).to eq(val.size)
60
+ expect(Hessian2.parse(bin)).to eq(val)
61
+ end
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -1,68 +1,68 @@
1
- require File.expand_path('../spec_helper', __FILE__)
2
-
3
- module Hessian2
4
- describe Writer do
5
- context "when long" do
6
-
7
- it "should write one-octet compact long (-x8 to xf, xe0 is 0) ::= [xd8-xef]" do
8
- (-0x08..0x0f).each do |val|
9
- bin = Hessian2.write(Hessian2::TypeWrapper.new(:long, val))
10
-
11
- expect(bin.unpack('C').first - 0xe0).to eq(val)
12
- expect(Hessian2.parse(bin)).to eq(val)
13
- end
14
- end
15
-
16
-
17
- it "should write two-octet compact long (-x800 to x7ff, xf8 is 0) ::= [xf0-xff] b0" do
18
- -0x800.step(0x7ff, 0x100).select{|x| !(-0x08..0x0f).include?(x)}.each do |val|
19
- bin = Hessian2.write(Hessian2::TypeWrapper.new(:long, val))
20
-
21
- b1, b0 = bin[0, 2].unpack('CC')
22
- expect(((b1 - 0xf8) << 8) + b0).to eq(val)
23
- expect(Hessian2.parse(bin)).to eq(val)
24
- end
25
- end
26
-
27
-
28
- it "should write three-octet compact long (-x40000 to x3ffff) ::= [x38-x3f] b1 b0" do
29
- -0x40000.step(0x3ffff, 0x10000).select{|x| !(-0x800..0x7ff).include?(x)}.each do |val|
30
- bin = Hessian2.write(Hessian2::TypeWrapper.new(:long, val))
31
-
32
- b2, b1, b0 = bin[0, 3].unpack('CCC')
33
- expect(((b2 - 0x3c) << 16) + (b1 << 8) + b0).to eq(val)
34
- expect(Hessian2.parse(bin)).to eq(val)
35
- end
36
- end
37
-
38
-
39
- it "should write long encoded as 32-bit int ('Y') ::= x59 b3 b2 b1 b0" do
40
- fixnum_max = 2 ** (0.size * 8 - 2) - 1
41
- fixnum_min = -(2 ** (0.size * 8 - 2))
42
-
43
- [ -0x80_000_000, 0x7f_fff_fff, -0x40001, 0x40000 ].each do |val|
44
- bin = Hessian2.write(val <= fixnum_max && val >= fixnum_min ? Hessian2::TypeWrapper.new(:long, val) : val)
45
-
46
- expect(bin[0]).to eq('Y')
47
- expect(bin[1, 4].unpack('l>').first).to eq(val)
48
- expect(Hessian2.parse(bin)).to eq(val)
49
- end
50
- end
51
-
52
-
53
- it "should write 64-bit signed long integer ('L') ::= 'L' b7 b6 b5 b4 b3 b2 b1 b0" do
54
- fixnum_max = 2 ** (0.size * 8 - 2) - 1
55
- fixnum_min = -(2 ** (0.size * 8 - 2))
56
-
57
- [ -0x8_000_000_000_000_000, 0x7_fff_fff_fff_fff_fff, -0x80_000_001, 0x80_000_000 ].each do |val|
58
- bin = Hessian2.write(val <= fixnum_max && val >= fixnum_min ? Hessian2::TypeWrapper.new(:long, val) : val)
59
-
60
- expect(bin[0]).to eq('L')
61
- expect(bin[1, 8].unpack('q>').first).to eq(val)
62
- expect(Hessian2.parse(bin)).to eq(val)
63
- end
64
- end
65
-
66
- end
67
- end
68
- end
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Hessian2
4
+ describe Writer do
5
+ context "when long" do
6
+
7
+ it "should write one-octet compact long (-x8 to xf, xe0 is 0) ::= [xd8-xef]" do
8
+ (-0x08..0x0f).each do |val|
9
+ bin = Hessian2.write(Hessian2::TypeWrapper.new(:long, val))
10
+
11
+ expect(bin.unpack('C').first - 0xe0).to eq(val)
12
+ expect(Hessian2.parse(bin)).to eq(val)
13
+ end
14
+ end
15
+
16
+
17
+ it "should write two-octet compact long (-x800 to x7ff, xf8 is 0) ::= [xf0-xff] b0" do
18
+ -0x800.step(0x7ff, 0x100).select{|x| !(-0x08..0x0f).include?(x)}.each do |val|
19
+ bin = Hessian2.write(Hessian2::TypeWrapper.new(:long, val))
20
+
21
+ b1, b0 = bin[0, 2].unpack('CC')
22
+ expect(((b1 - 0xf8) << 8) + b0).to eq(val)
23
+ expect(Hessian2.parse(bin)).to eq(val)
24
+ end
25
+ end
26
+
27
+
28
+ it "should write three-octet compact long (-x40000 to x3ffff) ::= [x38-x3f] b1 b0" do
29
+ -0x40000.step(0x3ffff, 0x10000).select{|x| !(-0x800..0x7ff).include?(x)}.each do |val|
30
+ bin = Hessian2.write(Hessian2::TypeWrapper.new(:long, val))
31
+
32
+ b2, b1, b0 = bin[0, 3].unpack('CCC')
33
+ expect(((b2 - 0x3c) << 16) + (b1 << 8) + b0).to eq(val)
34
+ expect(Hessian2.parse(bin)).to eq(val)
35
+ end
36
+ end
37
+
38
+
39
+ it "should write long encoded as 32-bit int ('Y') ::= x59 b3 b2 b1 b0" do
40
+ fixnum_max = 2 ** (0.size * 8 - 2) - 1
41
+ fixnum_min = -(2 ** (0.size * 8 - 2))
42
+
43
+ [ -0x80_000_000, 0x7f_fff_fff, -0x40001, 0x40000 ].each do |val|
44
+ bin = Hessian2.write(val <= fixnum_max && val >= fixnum_min ? Hessian2::TypeWrapper.new(:long, val) : val)
45
+
46
+ expect(bin[0]).to eq('Y')
47
+ expect(bin[1, 4].unpack('l>').first).to eq(val)
48
+ expect(Hessian2.parse(bin)).to eq(val)
49
+ end
50
+ end
51
+
52
+
53
+ it "should write 64-bit signed long integer ('L') ::= 'L' b7 b6 b5 b4 b3 b2 b1 b0" do
54
+ fixnum_max = 2 ** (0.size * 8 - 2) - 1
55
+ fixnum_min = -(2 ** (0.size * 8 - 2))
56
+
57
+ [ -0x8_000_000_000_000_000, 0x7_fff_fff_fff_fff_fff, -0x80_000_001, 0x80_000_000 ].each do |val|
58
+ bin = Hessian2.write(val <= fixnum_max && val >= fixnum_min ? Hessian2::TypeWrapper.new(:long, val) : val)
59
+
60
+ expect(bin[0]).to eq('L')
61
+ expect(bin[1, 8].unpack('q>').first).to eq(val)
62
+ expect(Hessian2.parse(bin)).to eq(val)
63
+ end
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -1,36 +1,36 @@
1
- require File.expand_path('../spec_helper', __FILE__)
2
-
3
- module Hessian2
4
- describe Writer do
5
- context "when map" do
6
- hash = { born_at: Time.new(2009, 5, 8), name: '大鸡', price: 99.99 }
7
-
8
- it "should write map with type ('M') ::= M type (value value)* Z" do
9
- type = 'Monkey'
10
- bin = Hessian2.write(Hessian2::TypeWrapper.new(type, hash))
11
-
12
- bytes = bin.each_byte
13
- expect([ bytes.next ].pack('C')).to eq('M')
14
- expect(Hessian2.parse_string(bytes)).to eq(type)
15
- _hash = Hessian2.parse(bin)
16
- expect([ _hash['born_at'], _hash['name'], _hash['price'] ]).to eq([ hash[:born_at], hash[:name], hash[:price] ])
17
- _hash2 = Hessian2.parse(bin, nil, symbolize_keys: true)
18
- expect(_hash2).to eq(hash)
19
- end
20
-
21
-
22
- it "should write untyped map ::= 'H' (value value)* 'Z'" do
23
- bin = Hessian2.write(hash)
24
-
25
- bytes = bin.each_byte
26
- expect(bin[0]).to eq('H')
27
- expect(bin[-1]).to eq('Z')
28
- _hash = Hessian2.parse(bin)
29
- expect([ _hash['born_at'], _hash['name'], _hash['price'] ]).to eq([ hash[:born_at], hash[:name], hash[:price] ])
30
- _hash2 = Hessian2.parse(bin, nil, symbolize_keys: true)
31
- expect(_hash2).to eq(hash)
32
- end
33
-
34
- end
35
- end
36
- end
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Hessian2
4
+ describe Writer do
5
+ context "when map" do
6
+ hash = { born_at: Time.new(2009, 5, 8), name: '大鸡', price: 99.99 }
7
+
8
+ it "should write map with type ('M') ::= M type (value value)* Z" do
9
+ type = 'Monkey'
10
+ bin = Hessian2.write(Hessian2::TypeWrapper.new(type, hash))
11
+
12
+ bytes = bin.each_byte
13
+ expect([ bytes.next ].pack('C')).to eq('M')
14
+ expect(Hessian2.parse_string(bytes)).to eq(type)
15
+ _hash = Hessian2.parse(bin)
16
+ expect([ _hash['born_at'], _hash['name'], _hash['price'] ]).to eq([ hash[:born_at], hash[:name], hash[:price] ])
17
+ _hash2 = Hessian2.parse(bin, nil, symbolize_keys: true)
18
+ expect(_hash2).to eq(hash)
19
+ end
20
+
21
+
22
+ it "should write untyped map ::= 'H' (value value)* 'Z'" do
23
+ bin = Hessian2.write(hash)
24
+
25
+ bytes = bin.each_byte
26
+ expect(bin[0]).to eq('H')
27
+ expect(bin[-1]).to eq('Z')
28
+ _hash = Hessian2.parse(bin)
29
+ expect([ _hash['born_at'], _hash['name'], _hash['price'] ]).to eq([ hash[:born_at], hash[:name], hash[:price] ])
30
+ _hash2 = Hessian2.parse(bin, nil, symbolize_keys: true)
31
+ expect(_hash2).to eq(hash)
32
+ end
33
+
34
+ end
35
+ end
36
+ end