hessian2 2.0.2 → 2.0.3
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.
- checksums.yaml +4 -4
- data/.gitignore +10 -10
- data/README.md +197 -197
- data/hessian2.gemspec +0 -2
- data/lib/hessian2/client.rb +57 -50
- data/lib/hessian2/constants.rb +164 -164
- data/lib/hessian2/fault.rb +3 -3
- data/lib/hessian2/handler.rb +18 -18
- data/lib/hessian2/hessian_client.rb +3 -3
- data/lib/hessian2/parser.rb +619 -619
- data/lib/hessian2/type_wrapper.rb +49 -49
- data/lib/hessian2/version.rb +3 -3
- data/lib/hessian2/writer.rb +499 -499
- data/lib/hessian2.rb +14 -14
- data/spec/binary_spec.rb +51 -51
- data/spec/boolean_spec.rb +26 -26
- data/spec/class_wrapper_spec.rb +52 -52
- data/spec/create_monkeys.rb +14 -14
- data/spec/date_spec.rb +45 -45
- data/spec/double_spec.rb +78 -78
- data/spec/int_spec.rb +54 -54
- data/spec/list_spec.rb +66 -66
- data/spec/long_spec.rb +68 -68
- data/spec/map_spec.rb +36 -36
- data/spec/null_spec.rb +17 -17
- data/spec/object_spec.rb +78 -78
- data/spec/ref_spec.rb +43 -43
- data/spec/spec_helper.rb +23 -23
- data/spec/string_spec.rb +61 -61
- data/spec/struct_wrapper_spec.rb +47 -47
- data/spec/type_wrapper_spec.rb +102 -102
- data/test/app.rb +24 -24
- data/test/async/em_http_asleep.rb +25 -25
- data/test/async/em_http_sleep.rb +25 -25
- data/test/async/monkey.asleep.rb +27 -27
- data/test/async/mysql2_aquery.rb +37 -37
- data/test/fault/monkey.undefined_method.rb +5 -5
- data/test/fault/monkey.wrong_arguments.rb +5 -5
- data/test/fiber_concurrency/em_http_asleep.rb +17 -17
- data/test/fiber_concurrency/em_http_sleep.rb +17 -17
- data/test/fiber_concurrency/monkey.asleep.fiber_aware.rb +18 -18
- data/test/fiber_concurrency/mysql2_query.rb +29 -29
- data/test/fiber_concurrency/net_http_asleep.rb +19 -19
- data/test/fiber_concurrency/net_http_sleep.rb +19 -19
- data/test/fibered_rainbows/Gemfile +15 -15
- data/test/fibered_rainbows/config.ru +11 -11
- data/test/fibered_rainbows/rainbows.rb +13 -13
- data/test/monkey_service.rb +16 -16
- data/test/prepare.rb +7 -7
- data/test/thread_concurrency/active_record_execute.rb +29 -29
- data/test/thread_concurrency/monkey.asleep.rb +22 -22
- data/test/thread_concurrency/net_http_asleep.rb +24 -24
- data/test/thread_concurrency/net_http_sleep.rb +24 -24
- data/test/threaded_rainbows/Gemfile +13 -13
- data/test/threaded_rainbows/config.ru +9 -9
- data/test/threaded_rainbows/rainbows.rb +13 -13
- metadata +4 -74
data/spec/int_spec.rb
CHANGED
@@ -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
|
data/spec/list_spec.rb
CHANGED
@@ -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
|
data/spec/long_spec.rb
CHANGED
@@ -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
|
data/spec/map_spec.rb
CHANGED
@@ -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
|
data/spec/null_spec.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
require File.expand_path('../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
module Hessian2
|
4
|
-
describe Writer do
|
5
|
-
context "when null" do
|
6
|
-
|
7
|
-
it "should write null ('N') ::= 'N'" do
|
8
|
-
val = nil
|
9
|
-
bin = Hessian2.write(val)
|
10
|
-
|
11
|
-
expect(bin).to eq('N')
|
12
|
-
expect(Hessian2.parse(bin)).to eq(val)
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
module Hessian2
|
4
|
+
describe Writer do
|
5
|
+
context "when null" do
|
6
|
+
|
7
|
+
it "should write null ('N') ::= 'N'" do
|
8
|
+
val = nil
|
9
|
+
bin = Hessian2.write(val)
|
10
|
+
|
11
|
+
expect(bin).to eq('N')
|
12
|
+
expect(Hessian2.parse(bin)).to eq(val)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/object_spec.rb
CHANGED
@@ -1,78 +1,78 @@
|
|
1
|
-
require File.expand_path('../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
module Hessian2
|
4
|
-
describe Writer do
|
5
|
-
context "when object" do
|
6
|
-
hash = { id: nil, born_at: Time.new(2009, 5, 8), name: '大鸡', price: 99.99 }
|
7
|
-
|
8
|
-
it "should write object type definition ('C') ::= 'C' string int string* and object with direct type ::= [x60-x6f] value*" do
|
9
|
-
[ 'Monkey', 'AnotherMonkey' ].each do |klass|
|
10
|
-
bin = Hessian2.write(Kernel.const_get(klass).new(hash))
|
11
|
-
|
12
|
-
bytes = bin.each_byte
|
13
|
-
expect([ bytes.next ].pack('C')).to eq('C')
|
14
|
-
expect(Hessian2.parse_string(bytes)).to eq(klass)
|
15
|
-
expect(Hessian2.parse_int(bytes)).to eq(4)
|
16
|
-
4.times{ Hessian2.parse_string(bytes) }
|
17
|
-
expect(bytes.next - 0x60).to eq(0)
|
18
|
-
_monkey = Hessian2.parse(bin)
|
19
|
-
expect([ _monkey.born_at, _monkey.name, _monkey.price ]).to eq([ hash[:born_at], hash[:name], hash[:price] ])
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
it "should write object instance ('O') ::= 'O' int value*" do
|
25
|
-
arr = []
|
26
|
-
17.times do |i|
|
27
|
-
arr << Hessian2::ClassWrapper.new("com.sun.java.Monkey#{i}", hash)
|
28
|
-
end
|
29
|
-
bin = Hessian2.write(arr)
|
30
|
-
|
31
|
-
bytes = bin.each_byte
|
32
|
-
|
33
|
-
# skip x58 int
|
34
|
-
bytes.next
|
35
|
-
Hessian2.parse_int(bytes)
|
36
|
-
|
37
|
-
# skip top 16
|
38
|
-
16.times do
|
39
|
-
bytes.next
|
40
|
-
Hessian2.parse_string(bytes)
|
41
|
-
Hessian2.parse_int(bytes)
|
42
|
-
4.times{ Hessian2.parse_string(bytes) }
|
43
|
-
bytes.next
|
44
|
-
4.times{ Hessian2.parse_bytes(bytes) }
|
45
|
-
end
|
46
|
-
|
47
|
-
# skip 17th class definition
|
48
|
-
bytes.next
|
49
|
-
Hessian2.parse_string(bytes)
|
50
|
-
Hessian2.parse_int(bytes)
|
51
|
-
4.times{ Hessian2.parse_string(bytes) }
|
52
|
-
|
53
|
-
expect([ bytes.next ].pack('C')).to eq('O')
|
54
|
-
expect(Hessian2.parse_int(bytes)).to eq(16)
|
55
|
-
|
56
|
-
_monkeys = Hessian2.parse(bin)
|
57
|
-
expect(_monkeys.size).to eq(17)
|
58
|
-
_monkeys.each do |_monkey|
|
59
|
-
expect([ _monkey.born_at, _monkey.name, _monkey.price ]).to eq([ hash[:born_at], hash[:name], hash[:price] ])
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should write ActiveRecord::Relation" do
|
64
|
-
val = Monkey.where(true).limit(2)
|
65
|
-
bin = Hessian2.write(val)
|
66
|
-
|
67
|
-
bytes = bin.each_byte
|
68
|
-
expect(bytes.next - 0x78).to eq(val.size)
|
69
|
-
|
70
|
-
born_at = Time.new(1989, 5, 8)
|
71
|
-
Hessian2.parse(bin).each_with_index do |_monkey, i|
|
72
|
-
expect([ _monkey.id, _monkey.name, _monkey.price, _monkey.born_at ]).to eq([ i + 1, "#{i}号猴", 0.25 * i, born_at + 86400 * i ])
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
module Hessian2
|
4
|
+
describe Writer do
|
5
|
+
context "when object" do
|
6
|
+
hash = { id: nil, born_at: Time.new(2009, 5, 8), name: '大鸡', price: 99.99 }
|
7
|
+
|
8
|
+
it "should write object type definition ('C') ::= 'C' string int string* and object with direct type ::= [x60-x6f] value*" do
|
9
|
+
[ 'Monkey', 'AnotherMonkey' ].each do |klass|
|
10
|
+
bin = Hessian2.write(Kernel.const_get(klass).new(hash))
|
11
|
+
|
12
|
+
bytes = bin.each_byte
|
13
|
+
expect([ bytes.next ].pack('C')).to eq('C')
|
14
|
+
expect(Hessian2.parse_string(bytes)).to eq(klass)
|
15
|
+
expect(Hessian2.parse_int(bytes)).to eq(4)
|
16
|
+
4.times{ Hessian2.parse_string(bytes) }
|
17
|
+
expect(bytes.next - 0x60).to eq(0)
|
18
|
+
_monkey = Hessian2.parse(bin)
|
19
|
+
expect([ _monkey.born_at, _monkey.name, _monkey.price ]).to eq([ hash[:born_at], hash[:name], hash[:price] ])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
it "should write object instance ('O') ::= 'O' int value*" do
|
25
|
+
arr = []
|
26
|
+
17.times do |i|
|
27
|
+
arr << Hessian2::ClassWrapper.new("com.sun.java.Monkey#{i}", hash)
|
28
|
+
end
|
29
|
+
bin = Hessian2.write(arr)
|
30
|
+
|
31
|
+
bytes = bin.each_byte
|
32
|
+
|
33
|
+
# skip x58 int
|
34
|
+
bytes.next
|
35
|
+
Hessian2.parse_int(bytes)
|
36
|
+
|
37
|
+
# skip top 16
|
38
|
+
16.times do
|
39
|
+
bytes.next
|
40
|
+
Hessian2.parse_string(bytes)
|
41
|
+
Hessian2.parse_int(bytes)
|
42
|
+
4.times{ Hessian2.parse_string(bytes) }
|
43
|
+
bytes.next
|
44
|
+
4.times{ Hessian2.parse_bytes(bytes) }
|
45
|
+
end
|
46
|
+
|
47
|
+
# skip 17th class definition
|
48
|
+
bytes.next
|
49
|
+
Hessian2.parse_string(bytes)
|
50
|
+
Hessian2.parse_int(bytes)
|
51
|
+
4.times{ Hessian2.parse_string(bytes) }
|
52
|
+
|
53
|
+
expect([ bytes.next ].pack('C')).to eq('O')
|
54
|
+
expect(Hessian2.parse_int(bytes)).to eq(16)
|
55
|
+
|
56
|
+
_monkeys = Hessian2.parse(bin)
|
57
|
+
expect(_monkeys.size).to eq(17)
|
58
|
+
_monkeys.each do |_monkey|
|
59
|
+
expect([ _monkey.born_at, _monkey.name, _monkey.price ]).to eq([ hash[:born_at], hash[:name], hash[:price] ])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should write ActiveRecord::Relation" do
|
64
|
+
val = Monkey.where(true).limit(2)
|
65
|
+
bin = Hessian2.write(val)
|
66
|
+
|
67
|
+
bytes = bin.each_byte
|
68
|
+
expect(bytes.next - 0x78).to eq(val.size)
|
69
|
+
|
70
|
+
born_at = Time.new(1989, 5, 8)
|
71
|
+
Hessian2.parse(bin).each_with_index do |_monkey, i|
|
72
|
+
expect([ _monkey.id, _monkey.name, _monkey.price, _monkey.born_at ]).to eq([ i + 1, "#{i}号猴", 0.25 * i, born_at + 86400 * i ])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|