hessian2 2.0.5 → 2.0.6
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 +203 -199
- data/lib/hessian2.rb +14 -14
- data/lib/hessian2/client.rb +57 -57
- 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 +506 -504
- 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 +46 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d080c91f86c463c0f5699a058ba3da810eb54789
|
4
|
+
data.tar.gz: 03aab8f86e1a4b4ea65e388cc4b9d0e33f896c4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e81a9a692e8f88d3b64f96adb5067fa039877efa5f3611fee185f59bda640b329d2e0f62372249bdb128ec762b5c6d1242ef09b81fcdd5969701308e5ff009b
|
7
|
+
data.tar.gz: a9d1819e4434745126b74c44b524fbaaed68abfa2c4c677820b7bed8f11ca5ff76947c6b5f1a4f17ae27ee83c02ce0b122a5a454ee83a07c1d19687ac742e1b0
|
data/.gitignore
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
*.gem
|
2
|
-
.bundle
|
3
|
-
Gemfile.lock
|
4
|
-
doc/*
|
5
|
-
pkg/*
|
6
|
-
spec/*.yml
|
7
|
-
spec/*.jpg
|
8
|
-
test/*.data
|
9
|
-
test/*.txt
|
10
|
-
test/*.yml
|
1
|
+
*.gem
|
2
|
+
.bundle
|
3
|
+
Gemfile.lock
|
4
|
+
doc/*
|
5
|
+
pkg/*
|
6
|
+
spec/*.yml
|
7
|
+
spec/*.jpg
|
8
|
+
test/*.data
|
9
|
+
test/*.txt
|
10
|
+
test/*.yml
|
data/README.md
CHANGED
@@ -1,199 +1,203 @@
|
|
1
|
-
# hessian2
|
2
|
-
|
3
|
-
like json, additionally, 麻绳2 parse your object as a struct.
|
4
|
-
|
5
|
-
hessian2 implements hessian 2.0 protocol. look [web services protocol](http://hessian.caucho.com/doc/hessian-ws.html) and [serialization protocol](http://hessian.caucho.com/doc/hessian-serialization.html).
|
6
|
-
|
7
|
-
Sequel::Mysql2::Dataset and ActiveRecord::Relation are also okey.
|
8
|
-
|
9
|
-
##
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
```
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
```
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
```
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
```
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
```
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
```
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
```
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
```
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
```
|
122
|
-
|
123
|
-
client
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
```
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
```
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
```
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
EM.
|
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
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
##
|
198
|
-
|
199
|
-
|
1
|
+
# hessian2
|
2
|
+
|
3
|
+
like json, additionally, 麻绳2 parse your object as a struct.
|
4
|
+
|
5
|
+
hessian2 implements hessian 2.0 protocol. look [web services protocol](http://hessian.caucho.com/doc/hessian-ws.html) and [serialization protocol](http://hessian.caucho.com/doc/hessian-serialization.html).
|
6
|
+
|
7
|
+
Sequel::Mysql2::Dataset and ActiveRecord::Relation are also okey.
|
8
|
+
|
9
|
+
## changelog
|
10
|
+
|
11
|
+
2.0.6: support ruby 2.4 Integer
|
12
|
+
|
13
|
+
## comparing
|
14
|
+
|
15
|
+
yajl-ruby: json, fast.
|
16
|
+
|
17
|
+
msgpack: binary, faster.
|
18
|
+
|
19
|
+
protobuf: encoding your object with schema.
|
20
|
+
|
21
|
+
marshal: powerful, fast, but ruby only.
|
22
|
+
|
23
|
+
hessian2: powerful as marshal but parse object to struct, clean api, smaller.
|
24
|
+
|
25
|
+
## install
|
26
|
+
|
27
|
+
```
|
28
|
+
gem install hessian2
|
29
|
+
```
|
30
|
+
|
31
|
+
## serializing
|
32
|
+
|
33
|
+
```
|
34
|
+
require 'hessian2'
|
35
|
+
```
|
36
|
+
|
37
|
+
``` ruby
|
38
|
+
attributes = { born_at: Time.new(2009, 5, 8), name: '大鸡', price: 99.99 }
|
39
|
+
monkey = Monkey.new(attributes)
|
40
|
+
#=> #<Monkey id: nil, born_at: "2009-05-08 00:00:00", name: "\u5927\u9E21", price: #<BigDecimal:2b7c568,'0.9998999999 999999E2',27(45)>>
|
41
|
+
|
42
|
+
bin = Hessian2.write(monkey)
|
43
|
+
```
|
44
|
+
|
45
|
+
## deserializing
|
46
|
+
|
47
|
+
``` ruby
|
48
|
+
monkey = Hessian2.parse(bin)
|
49
|
+
#=> #<struct id=nil, born_at=2009-05-08 00:00:00 +0800, name="\u5927\u9E21", price=99.99>
|
50
|
+
```
|
51
|
+
|
52
|
+
## struct wrapper
|
53
|
+
|
54
|
+
for hash and object, only send values that specified.
|
55
|
+
|
56
|
+
``` ruby
|
57
|
+
MonkeyStruct = Struct.new(:born_at, :name)
|
58
|
+
|
59
|
+
wrapped_monkey = Hessian2::StructWrapper.new(MonkeyStruct, monkey)
|
60
|
+
bin = Hessian2.write(wrapped_monkey)
|
61
|
+
```
|
62
|
+
|
63
|
+
parsing values-binary to a monkey struct
|
64
|
+
|
65
|
+
``` ruby
|
66
|
+
monkey = Hessian2.parse(bin, MonkeyStruct)
|
67
|
+
#=> #<struct born_at=2009-05-08 00:00:00 +0800, name="\u5927\u9E21">
|
68
|
+
```
|
69
|
+
|
70
|
+
monkeys
|
71
|
+
|
72
|
+
``` ruby
|
73
|
+
wrapped_monkeys = Hessian2::StructWrapper.new([MonkeyStruct], monkeys)
|
74
|
+
bin = Hessian2.write(wrapped_monkeys)
|
75
|
+
|
76
|
+
monkeys = Hessian2.parse(bin, [MonkeyStruct])
|
77
|
+
```
|
78
|
+
|
79
|
+
struct wrapper supports: hash, object, [hash, [object
|
80
|
+
|
81
|
+
## class wrapper
|
82
|
+
|
83
|
+
for statically typed languages.
|
84
|
+
|
85
|
+
``` ruby
|
86
|
+
wrapped_monkey = Hessian2::ClassWrapper.new('com.sun.java.Monkey', monkey)
|
87
|
+
```
|
88
|
+
|
89
|
+
monkeys
|
90
|
+
|
91
|
+
``` ruby
|
92
|
+
wrapped_monkeys = Hessian2::ClassWrapper.new('[com.sun.java.Monkey', monkeys)
|
93
|
+
```
|
94
|
+
|
95
|
+
class wrapper supports: hash, object, [hash, [object
|
96
|
+
|
97
|
+
## type wrapper
|
98
|
+
|
99
|
+
wrap a string to long
|
100
|
+
|
101
|
+
``` ruby
|
102
|
+
str = '-0x8_000_000_000_000_000'
|
103
|
+
heslong = Hessian2::TypeWrapper.new(:long, str)
|
104
|
+
```
|
105
|
+
|
106
|
+
wrap a file to binary
|
107
|
+
|
108
|
+
``` ruby
|
109
|
+
binstr = IO.binread(File.expand_path("../Lighthouse.jpg", __FILE__))
|
110
|
+
hesbin = Hessian2::TypeWrapper.new(:bin, binstr)
|
111
|
+
```
|
112
|
+
|
113
|
+
there are types: 'L', 'I', 'B', '[L', '[I', '[B', :long, :int, :bin, [:long], [:int], [:bin]
|
114
|
+
|
115
|
+
## :symbolize_keys parser option
|
116
|
+
|
117
|
+
``` ruby
|
118
|
+
bin = Hessian2.write(attributes)
|
119
|
+
hash = Hessian2.parse(bin, nil, symbolize_keys: true)
|
120
|
+
#=> {:born_at=>2009-05-08 00:00:00 +0800, :name=>"\u5927\u9E21", :price=>99.99}
|
121
|
+
```
|
122
|
+
|
123
|
+
## client
|
124
|
+
|
125
|
+
``` ruby
|
126
|
+
url = 'http://127.0.0.1:9292/monkey'
|
127
|
+
client = Hessian2::Client.new(url)
|
128
|
+
```
|
129
|
+
|
130
|
+
call remote method, send a monkey
|
131
|
+
|
132
|
+
``` ruby
|
133
|
+
client.send_monkey(monkey)
|
134
|
+
```
|
135
|
+
|
136
|
+
## service
|
137
|
+
|
138
|
+
extend hessian handler
|
139
|
+
|
140
|
+
``` ruby
|
141
|
+
class MonkeyService
|
142
|
+
extend Hessian2::Handler
|
143
|
+
|
144
|
+
def self.send_monkey(monkey)
|
145
|
+
# ...
|
146
|
+
end
|
147
|
+
```
|
148
|
+
|
149
|
+
handle request
|
150
|
+
|
151
|
+
``` ruby
|
152
|
+
post '/monkey' do
|
153
|
+
MonkeyService.handle(request.body.read)
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
157
|
+
## fiber_aware
|
158
|
+
|
159
|
+
fibered service, fiber aware client. use em-synchrony/em-http post.
|
160
|
+
|
161
|
+
``` ruby
|
162
|
+
client = Hessian2::Client.new(url, fiber_aware: true)
|
163
|
+
concurrency = 2
|
164
|
+
|
165
|
+
EM.synchrony do
|
166
|
+
EM::Synchrony::FiberIterator.new(0...10, concurrency).each do |i|
|
167
|
+
puts client.asleep
|
168
|
+
end
|
169
|
+
|
170
|
+
EM.stop
|
171
|
+
end
|
172
|
+
```
|
173
|
+
|
174
|
+
## async
|
175
|
+
|
176
|
+
evented service, asynchronous callbacks. use em-synchrony/em-http apost.
|
177
|
+
|
178
|
+
``` ruby
|
179
|
+
client = Hessian2::Client.new(url, async: true)
|
180
|
+
|
181
|
+
EM.run do
|
182
|
+
http = client.asleep
|
183
|
+
http.callback do |r|
|
184
|
+
puts Hessian2.parse_rpc(r.response)
|
185
|
+
EM.stop
|
186
|
+
end
|
187
|
+
|
188
|
+
http.errback do |r|
|
189
|
+
puts r.error
|
190
|
+
EM.stop
|
191
|
+
end
|
192
|
+
|
193
|
+
puts "posted."
|
194
|
+
end
|
195
|
+
```
|
196
|
+
|
197
|
+
## todo
|
198
|
+
|
199
|
+
supports packet and envelope
|
200
|
+
|
201
|
+
## authors
|
202
|
+
|
203
|
+
[takafan](http://cacafan.com)
|
data/lib/hessian2.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require 'hessian2/class_wrapper'
|
2
|
-
require 'hessian2/client'
|
3
|
-
require 'hessian2/fault'
|
4
|
-
require 'hessian2/handler'
|
5
|
-
require 'hessian2/hessian_client'
|
6
|
-
require 'hessian2/parser'
|
7
|
-
require 'hessian2/struct_wrapper'
|
8
|
-
require 'hessian2/type_wrapper'
|
9
|
-
require 'hessian2/version'
|
10
|
-
require 'hessian2/writer'
|
11
|
-
|
12
|
-
module Hessian2
|
13
|
-
extend Parser, Writer
|
14
|
-
end
|
1
|
+
require 'hessian2/class_wrapper'
|
2
|
+
require 'hessian2/client'
|
3
|
+
require 'hessian2/fault'
|
4
|
+
require 'hessian2/handler'
|
5
|
+
require 'hessian2/hessian_client'
|
6
|
+
require 'hessian2/parser'
|
7
|
+
require 'hessian2/struct_wrapper'
|
8
|
+
require 'hessian2/type_wrapper'
|
9
|
+
require 'hessian2/version'
|
10
|
+
require 'hessian2/writer'
|
11
|
+
|
12
|
+
module Hessian2
|
13
|
+
extend Parser, Writer
|
14
|
+
end
|