msgpack-rpc-stack 0.7.0 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/msgpack/rpc/client.rb +86 -4
- data/lib/msgpack/rpc/server.rb +107 -0
- data/lib/msgpack/rpc/version.rb +1 -1
- data/msgpack-rpc-stack.gemspec +3 -3
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b687418a1a9a272d68e0fdcf9dc186f9c7cb424d26bf1ea00257ee957e905bf
|
4
|
+
data.tar.gz: 0bc7c33e5e91070e051d4d3e2dbf7d44735e584e327a4a6992e573793ed1be40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17bff07e8d05495571b1a2492b5ad00c269b031ef526442eda3af8297886d7c7a7bce511ffce6334272962f7cab4f9f6b312af3e800bf2311159b91b375838cd
|
7
|
+
data.tar.gz: f197aaf7b86bb57f654a5cbe3ec632afcea0ab6716ade19ff5500517a9afdaa34ba852728e9eae2040aede41ade4e30ce93189d0a72d53601ecf7fe3aa861672
|
data/lib/msgpack/rpc/client.rb
CHANGED
@@ -12,6 +12,20 @@ require 'msgpack/rpc'
|
|
12
12
|
|
13
13
|
module MessagePack
|
14
14
|
module Rpc
|
15
|
+
#
|
16
|
+
# Module that implemented client protocol of MessagePack-RPC.
|
17
|
+
#
|
18
|
+
# @abstract
|
19
|
+
# Include from the class that implements the rpc client.
|
20
|
+
# When the client implementation class receives data from the
|
21
|
+
# communication line, it must call the receive_data() method and pass
|
22
|
+
# received data to the MessagePack::Rpc::Client module.
|
23
|
+
# Also, the client implementation class should define a method
|
24
|
+
# send_data() to actually send the data. Call this method from
|
25
|
+
# within the MessagePack::Rpc::Client module if necessary
|
26
|
+
# (Implement send_data() method to accept string objects in arguments).
|
27
|
+
# If you receive a protocol level error, override the on_error() method.
|
28
|
+
#
|
15
29
|
module Client
|
16
30
|
class << self
|
17
31
|
def included(klass)
|
@@ -67,6 +81,27 @@ module MessagePack
|
|
67
81
|
end
|
68
82
|
private :error_occured
|
69
83
|
|
84
|
+
#
|
85
|
+
# call the procedure of peer rpc server
|
86
|
+
#
|
87
|
+
# @param [Symbol] meth
|
88
|
+
# target procedure name.
|
89
|
+
#
|
90
|
+
# @param [Array] args
|
91
|
+
# arguments for procedure.
|
92
|
+
#
|
93
|
+
# @return [Integer]
|
94
|
+
# assigned mesaage id
|
95
|
+
#
|
96
|
+
# @yield [res, err]
|
97
|
+
# callback that is when the procedure call completes.
|
98
|
+
#
|
99
|
+
# @yieldparam [Object] res
|
100
|
+
# responce of procedure when procedure successed.
|
101
|
+
#
|
102
|
+
# @yieldparam [Object] err
|
103
|
+
# error data of procedure when procedure failed.
|
104
|
+
#
|
70
105
|
def call(meth, *args, &blk)
|
71
106
|
raise ArgumentError.new("handler is not spcified") if not blk
|
72
107
|
|
@@ -78,14 +113,34 @@ module MessagePack
|
|
78
113
|
return id
|
79
114
|
end
|
80
115
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
116
|
+
#
|
117
|
+
# cacel the call message
|
118
|
+
#
|
119
|
+
# @param [Integer] id
|
120
|
+
# message id of calling message (return value of
|
121
|
+
# MessagePack::Rpc::Client#call())
|
122
|
+
#
|
123
|
+
# @note
|
124
|
+
# When this method is called, the procedure call corresponding to
|
125
|
+
# the ID specified in the argument is cancelled.
|
126
|
+
#
|
85
127
|
def cancel(id)
|
86
128
|
session_map.delete(id)
|
87
129
|
end
|
88
130
|
|
131
|
+
#
|
132
|
+
# send the notification to peer rpc server
|
133
|
+
#
|
134
|
+
# @param [Symbol] meth
|
135
|
+
# notify name
|
136
|
+
#
|
137
|
+
# @param [Array] args
|
138
|
+
# argument for notification
|
139
|
+
#
|
140
|
+
def notify(meth, *args)
|
141
|
+
send_data([2, meth, args].to_msgpack)
|
142
|
+
end
|
143
|
+
|
89
144
|
def eval_response(resp)
|
90
145
|
if not resp.kind_of?(Array)
|
91
146
|
error_occured("responce is not array")
|
@@ -128,10 +183,27 @@ module MessagePack
|
|
128
183
|
end
|
129
184
|
private :eval_response
|
130
185
|
|
186
|
+
#
|
187
|
+
# emqueu the received datagram to communication buffer
|
188
|
+
#
|
189
|
+
# @param [Blob] data
|
190
|
+
# recevied data from rpc server.
|
191
|
+
#
|
192
|
+
# @note
|
193
|
+
# Use this method for datagram communication. \
|
194
|
+
# Use it when it is guaranteed that data is exchanged \
|
195
|
+
# in packets (it works a bit faster).
|
196
|
+
#
|
131
197
|
def receive_dgram(data)
|
132
198
|
eval_response(MessagePack.unpack(data, self.class.msgpack_options))
|
133
199
|
end
|
134
200
|
|
201
|
+
#
|
202
|
+
# emqueu the received data to communication buffer
|
203
|
+
#
|
204
|
+
# @param [Blob] data
|
205
|
+
# recevied data from rpc server.
|
206
|
+
#
|
135
207
|
def receive_stream(data)
|
136
208
|
begin
|
137
209
|
unpacker.feed_each(data) {|resp| eval_response(resp)}
|
@@ -145,6 +217,16 @@ module MessagePack
|
|
145
217
|
end
|
146
218
|
end
|
147
219
|
|
220
|
+
#
|
221
|
+
# define the notify method
|
222
|
+
#
|
223
|
+
# @param [Symbol] name
|
224
|
+
# notification name
|
225
|
+
#
|
226
|
+
# @yield [*args]
|
227
|
+
# callback that is when received the notification
|
228
|
+
# from peer rpc server.
|
229
|
+
#
|
148
230
|
def on(name, &blk)
|
149
231
|
raise ArgumentError.new("handler is not spcified") if not blk
|
150
232
|
notify_handler[name] = blk
|
data/lib/msgpack/rpc/server.rb
CHANGED
@@ -12,8 +12,89 @@ require 'msgpack/rpc'
|
|
12
12
|
|
13
13
|
module MessagePack
|
14
14
|
module Rpc
|
15
|
+
|
16
|
+
#
|
17
|
+
# Module that implemented server protocol of MessagePack-RPC.
|
18
|
+
#
|
19
|
+
# @abstract
|
20
|
+
# Include from the class that implements the rpc server. You can expose
|
21
|
+
# When the client implementation class receives data from the
|
22
|
+
# communication line, it must call the receive_data() method and pass
|
23
|
+
# received data to the MessagePack::Rpc::Server module.
|
24
|
+
# Also, the client implementation class should define a method
|
25
|
+
# send_data() to actually send the data. Call this method from
|
26
|
+
# within the MessagePack::Rpc::Server module if necessary
|
27
|
+
# (Implement send_data() method to accept string objects in arguments).
|
28
|
+
# If you receive a protocol level error, override the on_error() method.
|
29
|
+
# the methods defined in that class as RPC procedures.
|
30
|
+
#
|
15
31
|
module Server
|
16
32
|
class << self
|
33
|
+
#
|
34
|
+
# @!method msgpack_options(**opts)
|
35
|
+
# set MessagePack::Unpacker option.
|
36
|
+
#
|
37
|
+
# @example set :symbolize_keys option
|
38
|
+
# class Server
|
39
|
+
# include MessagePack::Rpc::Server
|
40
|
+
#
|
41
|
+
# msgpack_options = {:symbolize_keys => true}
|
42
|
+
#
|
43
|
+
# def test(data)
|
44
|
+
# # data's key are symbolized.
|
45
|
+
# return data[:data]
|
46
|
+
# end
|
47
|
+
# remote_public :test
|
48
|
+
# end
|
49
|
+
|
50
|
+
#
|
51
|
+
# @!method remote_public(name)
|
52
|
+
# expose syncronous procedure.
|
53
|
+
# The return value of the method exposed by this method is the
|
54
|
+
# return value of the procedure. If an exception occurs, the
|
55
|
+
# exception is returned as an error value.
|
56
|
+
#
|
57
|
+
# @param [Symbol] name
|
58
|
+
# target method name.
|
59
|
+
#
|
60
|
+
# @example expose syncronous procedure
|
61
|
+
# class Server
|
62
|
+
# include MessagePack::Rpc::Server
|
63
|
+
#
|
64
|
+
# def test(id)
|
65
|
+
# raise("id isnot defined") if id.nil?
|
66
|
+
# return "hello #{id}"
|
67
|
+
# end
|
68
|
+
# remote_public :test
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
|
72
|
+
#
|
73
|
+
# @!method remote_async(name)
|
74
|
+
# expose asynchronous procedure.
|
75
|
+
# The method exposed by this method takes a deferred object as its
|
76
|
+
# first argument. Returns the processing result asynchronously
|
77
|
+
# through this object.
|
78
|
+
#
|
79
|
+
# @param [Symbol] name
|
80
|
+
# target method name.
|
81
|
+
#
|
82
|
+
# @example expose asyncronous procedure
|
83
|
+
# class Server
|
84
|
+
# include MessagePack::Rpc::Server
|
85
|
+
#
|
86
|
+
# def test(df, id)
|
87
|
+
# if id.nil?
|
88
|
+
# df.reject("id isnot defined")
|
89
|
+
# else
|
90
|
+
# df.resolve("hello #{id}")
|
91
|
+
# end
|
92
|
+
# end
|
93
|
+
# remote_async :test
|
94
|
+
# end
|
95
|
+
#
|
96
|
+
|
97
|
+
# @!visibility protected
|
17
98
|
def included(klass)
|
18
99
|
m = Module.new {
|
19
100
|
@@error = Class.new(StandardError) {
|
@@ -197,10 +278,30 @@ module MessagePack
|
|
197
278
|
end
|
198
279
|
private :eval_message
|
199
280
|
|
281
|
+
#
|
282
|
+
# send the notification to peer rpc client
|
283
|
+
#
|
284
|
+
# @param [Symbol] meth
|
285
|
+
# notify name
|
286
|
+
#
|
287
|
+
# @param [Array] args
|
288
|
+
# argument for notification
|
289
|
+
#
|
200
290
|
def notify(meth, *args)
|
201
291
|
send_data([2, meth, args].to_msgpack)
|
202
292
|
end
|
203
293
|
|
294
|
+
#
|
295
|
+
# emqueu the received datagram to communication buffer
|
296
|
+
#
|
297
|
+
# @param [Blob] data
|
298
|
+
# recevied data from peer rpc client.
|
299
|
+
#
|
300
|
+
# @note
|
301
|
+
# Use this method for datagram communication.
|
302
|
+
# Use it when it is guaranteed that data is exchanged
|
303
|
+
# in packets (it works a bit faster).
|
304
|
+
#
|
204
305
|
def receive_dgram(data)
|
205
306
|
msg = MessagePack.unpack(data, self.class.msgpack_options)
|
206
307
|
|
@@ -211,6 +312,12 @@ module MessagePack
|
|
211
312
|
eval_message(msg)
|
212
313
|
end
|
213
314
|
|
315
|
+
#
|
316
|
+
# emqueu the received data to communication buffer
|
317
|
+
#
|
318
|
+
# @param [Blob] data
|
319
|
+
# recevied data from peer rpc client.
|
320
|
+
#
|
214
321
|
def receive_stream(data)
|
215
322
|
begin
|
216
323
|
unpacker.feed_each(data) {|msg| eval_message(msg)}
|
data/lib/msgpack/rpc/version.rb
CHANGED
data/msgpack-rpc-stack.gemspec
CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
|
36
36
|
spec.required_ruby_version = ">= 2.4.0"
|
37
37
|
|
38
|
-
spec.add_development_dependency "bundler", "
|
39
|
-
spec.add_development_dependency "rake", "
|
40
|
-
spec.add_dependency "msgpack", "
|
38
|
+
spec.add_development_dependency "bundler", ">= 2.1"
|
39
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
40
|
+
spec.add_dependency "msgpack", ">= 1.6.0"
|
41
41
|
end
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msgpack-rpc-stack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroshi Kuwagata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: msgpack
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.6.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
54
|
+
version: 1.6.0
|
55
55
|
description: A module of implementation MessagePack-RPC stack
|
56
56
|
email:
|
57
57
|
- kgt9221@gmail.com
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
|
-
rubygems_version: 3.
|
97
|
+
rubygems_version: 3.4.8
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: MessagePack-RPC module
|