pipe_rpc 1.1.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/msgpack_config.rb +27 -0
- data/lib/pipe_rpc/client.rb +6 -0
- data/lib/pipe_rpc/hub_message.rb +2 -1
- data/lib/pipe_rpc/hub_request_result.rb +1 -1
- data/lib/pipe_rpc/hub_socket.rb +24 -8
- data/lib/pipe_rpc/result_response.rb +1 -15
- data/lib/pipe_rpc/version.rb +1 -1
- data/lib/pipe_rpc.rb +1 -5
- data/pipe_rpc.gemspec +2 -2
- metadata +9 -11
- data/lib/hash.rb +0 -5
- data/lib/pipe_rpc/hub_socket_incoming.rb +0 -20
- data/lib/pipe_rpc/hub_socket_outgoing.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb0f50e52b37b279be08b1044701ff5dc9fdb53f
|
4
|
+
data.tar.gz: 9aa8ac09ca6ad298acba5869c649a707c2d5bf4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57dd76c93512192edbe0878d59887a09d9177d0db745243bc4549c226e0e9f908fcd72eb1a195dfa0bdc9009e26bd471745abdedceae9d49a84f04a776a8f640
|
7
|
+
data.tar.gz: cc9327c2967955c7c82790f919acc1e7ed33f93eb596a91b88e7bc92b149d9f430e646dd15b674fe562b23454818b5c38ed244d4f83082179f777b3f57c2998d
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# PipeRpc
|
2
2
|
|
3
|
-
PipeRpc was designed so parent und child processes can call each other's
|
3
|
+
PipeRpc was designed so parent und child processes can call each other's
|
4
|
+
methods. It uses a protocol similar to JSON-RPC but serializes the payloads
|
5
|
+
with [msgpack](http://msgpack.org/).
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'msgpack'
|
2
|
+
|
3
|
+
# Serialize objects to strings by default
|
4
|
+
class Object
|
5
|
+
def to_msgpack(packer)
|
6
|
+
packer.pack(to_s)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.from_msgpack(packed)
|
10
|
+
packed.unpack('A*').first
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Support serialization of symbols
|
15
|
+
MessagePack::DefaultFactory.register_type(0x01, Symbol)
|
16
|
+
|
17
|
+
# For compatibility with the msgpack implementation in mruby
|
18
|
+
MessagePack::Error = MessagePack::UnpackError
|
19
|
+
|
20
|
+
# The msgpack implementation in mruby supports an ext type for classes
|
21
|
+
class Class
|
22
|
+
alias_method :to_msgpack_ext, :to_msgpack
|
23
|
+
end
|
24
|
+
class << Class
|
25
|
+
alias_method :from_msgpack_ext, :from_msgpack
|
26
|
+
end
|
27
|
+
MessagePack::DefaultFactory.register_type(0x02, Class)
|
data/lib/pipe_rpc/client.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module PipeRpc
|
2
2
|
class Client < BasicObject
|
3
|
+
undef_method :instance_eval unless ::Object.const_defined?(:MRUBY_VERSION)
|
4
|
+
undef_method :instance_exec unless ::Object.const_defined?(:MRUBY_VERSION)
|
5
|
+
|
3
6
|
def initialize(server = :default, hub)
|
4
7
|
@server = server.to_sym
|
5
8
|
@hub = hub
|
@@ -9,6 +12,9 @@ module PipeRpc
|
|
9
12
|
request = Client::Request.new(server: @server, method: method, arguments: args)
|
10
13
|
@hub.requests.evaluate(request)
|
11
14
|
end
|
15
|
+
alias __send__ method_missing
|
16
|
+
alias send method_missing
|
17
|
+
alias public_send method_missing
|
12
18
|
|
13
19
|
def to_s
|
14
20
|
"<Client:#{@server.to_s}>"
|
data/lib/pipe_rpc/hub_message.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
module PipeRpc
|
2
|
+
PipeRpcErrorResponse = ErrorResponse
|
2
3
|
class Hub
|
3
4
|
class Message
|
4
5
|
def initialize(hub, body)
|
@@ -47,7 +48,7 @@ module PipeRpc
|
|
47
48
|
def guarded
|
48
49
|
yield
|
49
50
|
rescue => e
|
50
|
-
@hub.socket.write
|
51
|
+
@hub.socket.write PipeRpcErrorResponse.new(id: @body[:id], error: { code: -32600,
|
51
52
|
data: { message: e.message } })
|
52
53
|
nil
|
53
54
|
end
|
data/lib/pipe_rpc/hub_socket.rb
CHANGED
@@ -10,18 +10,26 @@ module PipeRpc
|
|
10
10
|
|
11
11
|
def read
|
12
12
|
raise ClosedError if @input.closed?
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
|
14
|
+
# infinite #readpartial that also works with mruby-restricted_io
|
15
|
+
packed = ''
|
16
|
+
loop do
|
17
|
+
packed << @input.sysread(2*16)
|
18
|
+
break unless @input.class.select([@input], nil, nil, 0)
|
19
|
+
end
|
20
|
+
|
21
|
+
unpack(packed).tap do |unpacked|
|
22
|
+
@on_received.each{ |cb| cb.call(unpacked) }
|
23
|
+
end
|
24
|
+
rescue MessagePack::Error => e
|
25
|
+
write ErrorResponse.new(id: nil, error: { code: -32700, data: { message: "MessagePack: #{e.message}" } })
|
18
26
|
end
|
19
27
|
|
20
28
|
def write(obj)
|
21
29
|
raise ClosedError if @output.closed?
|
22
|
-
|
23
|
-
|
24
|
-
@output.
|
30
|
+
payload = obj.to_h
|
31
|
+
@on_sent.each{ |callback| callback.call(payload) }
|
32
|
+
@output.syswrite payload.to_msgpack
|
25
33
|
end
|
26
34
|
|
27
35
|
def on_sent(&on_sent)
|
@@ -36,5 +44,13 @@ module PipeRpc
|
|
36
44
|
@input.close
|
37
45
|
@output.close
|
38
46
|
end
|
47
|
+
|
48
|
+
def unpack(packed)
|
49
|
+
if ::Object.const_defined?(:MRUBY_VERSION)
|
50
|
+
MessagePack.unpack(packed, true) # to create unknown symbols in mruby
|
51
|
+
else
|
52
|
+
MessagePack.unpack(packed)
|
53
|
+
end
|
54
|
+
end
|
39
55
|
end
|
40
56
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module PipeRpc
|
2
2
|
class ResultResponse
|
3
3
|
def initialize(args = {})
|
4
|
-
@result =
|
4
|
+
@result = args.fetch(:result)
|
5
5
|
@id = args.fetch(:id)
|
6
6
|
end
|
7
7
|
|
@@ -10,19 +10,5 @@ module PipeRpc
|
|
10
10
|
def to_h
|
11
11
|
{ id: id, result: result }
|
12
12
|
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def sanitize(result)
|
17
|
-
if true == result or false == result or nil == result or result.is_a?(String) or result.is_a?(Numeric)
|
18
|
-
result
|
19
|
-
elsif result.is_a?(Array)
|
20
|
-
result.map{ |v| sanitize(v) }
|
21
|
-
elsif result.is_a?(Hash)
|
22
|
-
Hash[result.map{ |k,v| [sanitize(k), sanitize(v)] }]
|
23
|
-
else
|
24
|
-
result.to_s
|
25
|
-
end
|
26
|
-
end
|
27
13
|
end
|
28
14
|
end
|
data/lib/pipe_rpc/version.rb
CHANGED
data/lib/pipe_rpc.rb
CHANGED
data/pipe_rpc.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = %q{RPC between parent and child process over pipes}
|
13
13
|
spec.description = %q{PipeRpc was designed so parent und child processes can call each other's
|
14
|
-
methods. It uses a
|
14
|
+
methods. It uses a protocol similar to JSON-RPC but serializing with msgpack.}
|
15
15
|
spec.homepage = "https://github.com/christopheraue/ruby-pipe_rpc"
|
16
16
|
spec.license = "MIT"
|
17
17
|
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_runtime_dependency "
|
22
|
+
spec.add_runtime_dependency "msgpack", "~> 1.0"
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.8"
|
24
24
|
spec.add_development_dependency "rspec", "~> 3.4"
|
25
25
|
spec.add_development_dependency "rspec-its"
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pipe_rpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Aue
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: msgpack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
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: '0'
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
version: '0.2'
|
83
83
|
description: |-
|
84
84
|
PipeRpc was designed so parent und child processes can call each other's
|
85
|
-
methods. It uses a
|
85
|
+
methods. It uses a protocol similar to JSON-RPC but serializing with msgpack.
|
86
86
|
email:
|
87
87
|
- mail@christopheraue.net
|
88
88
|
executables: []
|
@@ -96,7 +96,7 @@ files:
|
|
96
96
|
- Gemfile
|
97
97
|
- README.md
|
98
98
|
- Rakefile
|
99
|
-
- lib/
|
99
|
+
- lib/msgpack_config.rb
|
100
100
|
- lib/pipe_rpc.rb
|
101
101
|
- lib/pipe_rpc/client.rb
|
102
102
|
- lib/pipe_rpc/client_request.rb
|
@@ -118,8 +118,6 @@ files:
|
|
118
118
|
- lib/pipe_rpc/hub_requests.rb
|
119
119
|
- lib/pipe_rpc/hub_servers.rb
|
120
120
|
- lib/pipe_rpc/hub_socket.rb
|
121
|
-
- lib/pipe_rpc/hub_socket_incoming.rb
|
122
|
-
- lib/pipe_rpc/hub_socket_outgoing.rb
|
123
121
|
- lib/pipe_rpc/request.rb
|
124
122
|
- lib/pipe_rpc/result_response.rb
|
125
123
|
- lib/pipe_rpc/version.rb
|
data/lib/hash.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module PipeRpc
|
2
|
-
class Hub::Socket
|
3
|
-
class Incoming
|
4
|
-
def initialize(payload)
|
5
|
-
@payload = payload
|
6
|
-
end
|
7
|
-
|
8
|
-
def to_h
|
9
|
-
@hash ||= JSON.load(@payload).symbolize_keys.tap do |hash|
|
10
|
-
hash[:error] = hash[:error].symbolize_keys if hash[:error]
|
11
|
-
hash[:error][:data] = hash[:error][:data].symbolize_keys if hash[:error] and hash[:error][:data]
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def trigger(callbacks)
|
16
|
-
callbacks.each{ |callback| callback.call(to_h) }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module PipeRpc
|
2
|
-
class Hub::Socket
|
3
|
-
class Outgoing
|
4
|
-
def initialize(object)
|
5
|
-
@object = object
|
6
|
-
end
|
7
|
-
|
8
|
-
def to_h
|
9
|
-
@hash ||= @object.to_h
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_payload
|
13
|
-
@payload ||= JSON.dump(to_h)
|
14
|
-
end
|
15
|
-
|
16
|
-
def trigger(callbacks)
|
17
|
-
callbacks.each{ |callback| callback.call(to_h) }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|