capn_proto-rpc 0.1.1.alpha.rpc
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +19 -0
- data/Gemfile +2 -0
- data/LICENSE +19 -0
- data/README.md +249 -0
- data/Rakefile +44 -0
- data/capn_proto.gemspec +37 -0
- data/examples/addressbook.bin +0 -0
- data/examples/addressbook.capnp +31 -0
- data/examples/create_test_data.py +39 -0
- data/examples/example.rb +38 -0
- data/ext/capn_proto/.ycm_extra_conf.py +65 -0
- data/ext/capn_proto/EzRpc_client.cc +52 -0
- data/ext/capn_proto/EzRpc_client.h +21 -0
- data/ext/capn_proto/EzRpc_server.cc +79 -0
- data/ext/capn_proto/EzRpc_server.h +32 -0
- data/ext/capn_proto/call_context.cc +67 -0
- data/ext/capn_proto/call_context.h +25 -0
- data/ext/capn_proto/capability_client.cc +47 -0
- data/ext/capn_proto/capability_client.h +21 -0
- data/ext/capn_proto/class_builder.cc +80 -0
- data/ext/capn_proto/class_builder.h +72 -0
- data/ext/capn_proto/cxx_compiler.rb +126 -0
- data/ext/capn_proto/dynamic_capability_client.cc +73 -0
- data/ext/capn_proto/dynamic_capability_client.h +22 -0
- data/ext/capn_proto/dynamic_list_builder.cc +123 -0
- data/ext/capn_proto/dynamic_list_builder.h +27 -0
- data/ext/capn_proto/dynamic_list_reader.cc +63 -0
- data/ext/capn_proto/dynamic_list_reader.h +25 -0
- data/ext/capn_proto/dynamic_object_builder.cc +57 -0
- data/ext/capn_proto/dynamic_object_builder.h +22 -0
- data/ext/capn_proto/dynamic_object_reader.cc +56 -0
- data/ext/capn_proto/dynamic_object_reader.h +22 -0
- data/ext/capn_proto/dynamic_struct_builder.cc +180 -0
- data/ext/capn_proto/dynamic_struct_builder.h +34 -0
- data/ext/capn_proto/dynamic_struct_reader.cc +69 -0
- data/ext/capn_proto/dynamic_struct_reader.h +25 -0
- data/ext/capn_proto/dynamic_value_builder.cc +53 -0
- data/ext/capn_proto/dynamic_value_builder.h +13 -0
- data/ext/capn_proto/dynamic_value_reader.cc +55 -0
- data/ext/capn_proto/dynamic_value_reader.h +13 -0
- data/ext/capn_proto/exception.cc +34 -0
- data/ext/capn_proto/exception.h +20 -0
- data/ext/capn_proto/extconf.rb +32 -0
- data/ext/capn_proto/field_list.cc +51 -0
- data/ext/capn_proto/field_list.h +23 -0
- data/ext/capn_proto/flat_array_message_reader.cc +61 -0
- data/ext/capn_proto/flat_array_message_reader.h +21 -0
- data/ext/capn_proto/init.cc +71 -0
- data/ext/capn_proto/interface_method.cc +38 -0
- data/ext/capn_proto/interface_method.h +21 -0
- data/ext/capn_proto/interface_schema.cc +51 -0
- data/ext/capn_proto/interface_schema.h +26 -0
- data/ext/capn_proto/list_nested_node_reader.cc +53 -0
- data/ext/capn_proto/list_nested_node_reader.h +24 -0
- data/ext/capn_proto/malloc_message_builder.cc +51 -0
- data/ext/capn_proto/malloc_message_builder.h +21 -0
- data/ext/capn_proto/message_builder.cc +22 -0
- data/ext/capn_proto/message_builder.h +17 -0
- data/ext/capn_proto/message_reader.cc +30 -0
- data/ext/capn_proto/message_reader.h +17 -0
- data/ext/capn_proto/nested_node_reader.cc +42 -0
- data/ext/capn_proto/nested_node_reader.h +21 -0
- data/ext/capn_proto/parsed_schema.cc +65 -0
- data/ext/capn_proto/parsed_schema.h +24 -0
- data/ext/capn_proto/rb.cc +0 -0
- data/ext/capn_proto/rb.h +0 -0
- data/ext/capn_proto/remote_promise.cc +116 -0
- data/ext/capn_proto/remote_promise.h +30 -0
- data/ext/capn_proto/ruby_capability_server.cc +23 -0
- data/ext/capn_proto/ruby_capability_server.h +21 -0
- data/ext/capn_proto/ruby_capn_proto.cc +4 -0
- data/ext/capn_proto/ruby_capn_proto.h +42 -0
- data/ext/capn_proto/schema_node_reader.cc +59 -0
- data/ext/capn_proto/schema_node_reader.h +23 -0
- data/ext/capn_proto/schema_parser.cc +61 -0
- data/ext/capn_proto/schema_parser.h +20 -0
- data/ext/capn_proto/stream_fd_message_reader.cc +59 -0
- data/ext/capn_proto/stream_fd_message_reader.h +21 -0
- data/ext/capn_proto/struct_schema.cc +59 -0
- data/ext/capn_proto/struct_schema.h +23 -0
- data/ext/capn_proto/util.cc +30 -0
- data/ext/capn_proto/util.h +17 -0
- data/lib/capn_proto.rb +231 -0
- data/lib/capn_proto/version.rb +3 -0
- data/media/captain_proto.png +0 -0
- data/media/captain_proto_small.png +0 -0
- data/spec/addressbook.bin +0 -0
- data/spec/addressbook.capnp +31 -0
- data/spec/capn_proto_spec.rb +80 -0
- data/spec/create_test_data.py +38 -0
- data/spec/spec_helper.rb +8 -0
- data/tests/hidraCordatus.capnp +16 -0
- data/tests/hidraCordatusEmployer.rb +33 -0
- data/tests/hidraCordatusMaster.rb +51 -0
- metadata +216 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bb0376733f65b4d375a29c42f945b0ee1bcec8b0
|
4
|
+
data.tar.gz: b61f3ba9cf9404bfa36b62b92bc9c99b5c96e5ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46a976fc012163fed9d32b674094cf62d3b829696a3aecdfd14b269e6689cca3eeec395b30b4527da3e9304eaff957de6edfec1a9d76209b176913e4c384187d
|
7
|
+
data.tar.gz: 823596f7f4696caaed82e8c30fad403d7f189ad6c08a1ec10fb599112a0684d3c03ad989611551536009b41608664dfdd98dec07219e1aabe73ea3f6748f4727
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 1.9.2
|
5
|
+
- 1.9.3
|
6
|
+
- 2.0.0
|
7
|
+
|
8
|
+
compiler: gcc
|
9
|
+
|
10
|
+
before_install:
|
11
|
+
- sudo apt-get install autoconf automake libtool autotools-dev
|
12
|
+
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
|
13
|
+
- sudo apt-get -qq update
|
14
|
+
- sudo apt-get -qq install g++-4.8 libstdc++-4.8-dev
|
15
|
+
- sudo update-alternatives --quiet --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60
|
16
|
+
--slave /usr/bin/g++ g++ /usr/bin/g++-4.8
|
17
|
+
--slave /usr/bin/gcov gcov /usr/bin/gcov-4.8
|
18
|
+
- sudo update-alternatives --quiet --set gcc /usr/bin/gcc-4.8
|
19
|
+
- git clone --depth=1 https://github.com/kentonv/capnproto.git && cd capnproto/c++ && ./setup-autotools.sh && autoreconf -i && ./configure && make -j6 check && sudo make install && sudo ldconfig && cd ../..
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2013 Charles Strahan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,249 @@
|
|
1
|
+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/cstrahan/capnp-ruby/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
2
|
+
|
3
|
+
![Cap'n Proto][logo]
|
4
|
+
|
5
|
+
# Ruby Edition
|
6
|
+
|
7
|
+
This here is a [Ruby][ruby] wrapper for the official C++ implementation of [Cap'n Proto][capnp].
|
8
|
+
|
9
|
+
[![Build Status][travis-badge]][travis-link]
|
10
|
+
|
11
|
+
# Installing
|
12
|
+
|
13
|
+
First [install libcapnp][libcapnp-install], then install the gem:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
gem install capn_proto --pre
|
17
|
+
```
|
18
|
+
|
19
|
+
The native extension for this gem requires a C++ compiler with C++11 features, so use the same C++ compiler and flags that you used to compile libcapnp (e.g. `CXX` and `CXXFLAGS`). As an OSX user, having followed the [instructions for installing libcapnp on OSX][libcapnp-install], the correct incantation is as follows:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
CXX=$HOME/clang-3.2/bin/clang++ gem install capn_proto --pre
|
23
|
+
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
# Structs Example
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'capn_proto'
|
31
|
+
|
32
|
+
module AddressBook extend CapnProto::SchemaLoader
|
33
|
+
load_schema("addressbook.capnp")
|
34
|
+
end
|
35
|
+
|
36
|
+
def write_address_book(file)
|
37
|
+
addresses = AddressBook::AddressBook.new_message
|
38
|
+
people = addresses.initPeople(2)
|
39
|
+
|
40
|
+
alice = people[0]
|
41
|
+
alice.id = 123
|
42
|
+
alice.name = 'Alice'
|
43
|
+
alice.email = 'alice@example.com'
|
44
|
+
alice_phones = alice.initPhones(1)
|
45
|
+
alice_phones[0].number = "555-1212"
|
46
|
+
alice_phones[0].type = 'mobile'
|
47
|
+
alice.employment.school = "MIT"
|
48
|
+
|
49
|
+
bob = people[1]
|
50
|
+
bob.id = 456
|
51
|
+
bob.name = 'Bob'
|
52
|
+
bob.email = 'bob@example.com'
|
53
|
+
bob_phones = bob.initPhones(2)
|
54
|
+
bob_phones[0].number = "555-4567"
|
55
|
+
bob_phones[0].type = 'home'
|
56
|
+
bob_phones[1].number = "555-7654"
|
57
|
+
bob_phones[1].type = 'work'
|
58
|
+
bob.employment.unemployed = nil
|
59
|
+
|
60
|
+
addresses.write(file)
|
61
|
+
end
|
62
|
+
|
63
|
+
def print_address_book(file)
|
64
|
+
addresses = AddressBook::AddressBook.read_from(file)
|
65
|
+
|
66
|
+
addresses.people.each do |person|
|
67
|
+
puts "#{person.name} : #{person.email}"
|
68
|
+
|
69
|
+
person.phones.each do |phone|
|
70
|
+
puts "#{phone.type} : #{phone.number}"
|
71
|
+
end
|
72
|
+
|
73
|
+
if person.employment.unemployed?
|
74
|
+
puts "unemployed"
|
75
|
+
if person.employment.employer?
|
76
|
+
puts "employer: #{person.employment.employer}"
|
77
|
+
if person.employment.school?
|
78
|
+
puts "student at: #{person.employment.school}"
|
79
|
+
if person.employment.selfEmployed?
|
80
|
+
puts "self employed"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
if __FILE__ == $0
|
86
|
+
file = File.open("addressbook.bin", "wb")
|
87
|
+
write_address_book(file)
|
88
|
+
|
89
|
+
file = File.open("addressbook.bin", "rb")
|
90
|
+
print_address_book(file)
|
91
|
+
end
|
92
|
+
```
|
93
|
+
# RPC Client Example
|
94
|
+
note: the schema file, client example and the server example can be found in lib/tests as a minitest.
|
95
|
+
|
96
|
+
The following examples uses this schema:
|
97
|
+
```CapnProto
|
98
|
+
|
99
|
+
struct Task {
|
100
|
+
dataint @0 :Int32;
|
101
|
+
madeBy @1 :Text;
|
102
|
+
}
|
103
|
+
|
104
|
+
interface Employer {
|
105
|
+
getWorker @0 () -> ( worker :Worker );
|
106
|
+
}
|
107
|
+
|
108
|
+
interface Worker {
|
109
|
+
put23 @0 (taskToProcess :Task) -> (taskProcessed :Task);
|
110
|
+
}
|
111
|
+
|
112
|
+
```
|
113
|
+
Load all the schemas and methods that will be used then create an EzRpcClient and from it get our client.
|
114
|
+
```ruby
|
115
|
+
|
116
|
+
module Hydra extend CapnProto::SchemaLoader
|
117
|
+
load_schema('./tests/hidraCordatus.capnp')
|
118
|
+
end
|
119
|
+
|
120
|
+
employer_schema = Hydra::Employer.schema
|
121
|
+
get_worker_method = Hydra::Employer.method! 'getWorker'
|
122
|
+
put23method = Hydra::Worker.method! 'put23'
|
123
|
+
|
124
|
+
ezclient = CapnProto::EzRpcClient.new("127.0.0.1:1337",employer_schema)
|
125
|
+
client = ezclient.client
|
126
|
+
|
127
|
+
```
|
128
|
+
Create a request of the method "getWorker" who is in the variable get_worker_method above.
|
129
|
+
Then, send it storing the pipelined request.
|
130
|
+
```ruby
|
131
|
+
request = client.request(get_worker_method)
|
132
|
+
pipelinedRequest = request.send
|
133
|
+
```
|
134
|
+
get the returned "worker" set the method that we want to request on it and then set
|
135
|
+
the parameters to be requested, in this case we set dataint to 0.
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
pipelinedRequest.get('worker').method = put23method
|
139
|
+
pipelinedRequest.taskToProcess.dataint(0)
|
140
|
+
```
|
141
|
+
now we wait for the results (note that this is the only line that blocks). while we are waiting
|
142
|
+
the Global interpreter lock is released so we can run ruby code on other threads.
|
143
|
+
Also note that we use ezclient as a waitscope.
|
144
|
+
```ruby
|
145
|
+
results = pipelinedRequest.send.wait(ezclient)
|
146
|
+
puts results.taskProcessed.dataint
|
147
|
+
puts results.taskProcessed.madeBy
|
148
|
+
```
|
149
|
+
|
150
|
+
# RPC server Example
|
151
|
+
```ruby
|
152
|
+
|
153
|
+
module Hydra extend CapnProto::SchemaLoader
|
154
|
+
load_schema('./tests/hidraCordatus.capnp')
|
155
|
+
end
|
156
|
+
|
157
|
+
class WorkerServer < CapnProto::CapabilityServer
|
158
|
+
def initialize(i)
|
159
|
+
@madeBy = "made by worker ##{i}"
|
160
|
+
super(Hydra::Worker.schema)
|
161
|
+
end
|
162
|
+
|
163
|
+
def put23(context)
|
164
|
+
n = context.getParams.taskToProcess.dataint
|
165
|
+
context.getResults.taskProcessed.dataint = n + 23
|
166
|
+
context.getResults.taskProcessed.madeBy = @madeBy
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
class EmployerServer < CapnProto::CapabilityServer
|
171
|
+
def initialize(wp)
|
172
|
+
@worker_pool = wp
|
173
|
+
@currentWorker = 0
|
174
|
+
super(Hydra::Employer.schema)
|
175
|
+
end
|
176
|
+
|
177
|
+
def get_a_Worker
|
178
|
+
@currentWorker += 1
|
179
|
+
@worker_pool[@currentWorker % @worker_pool.size]
|
180
|
+
end
|
181
|
+
|
182
|
+
def getWorker(context)
|
183
|
+
context.getResults.worker = get_a_Worker
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
```
|
188
|
+
note that the name of the methods is exactly the same as the name of the function that is defined on the schema and recieves only one argument. This argument is a callContext, you can use the method **getParams** to get the parameters passed to the called method or
|
189
|
+
use **getResults** to set the results of the request.
|
190
|
+
regarding to the example, EmployerServer will serve WorkerServers to the clients.
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
workers = []
|
194
|
+
10.times do |i|
|
195
|
+
workers << WorkerServer.new(i)
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
e = CapnProto::EzRpcServer.new(EmployerServer.new(workers), "*:1337")
|
200
|
+
puts "serving EmployerServer on 1337..."
|
201
|
+
e.run
|
202
|
+
|
203
|
+
```
|
204
|
+
create ten workers, then a EzRpcServer wich binds to port 1337. Then run it.
|
205
|
+
```
|
206
|
+
the results of running the server/client pair is :
|
207
|
+
|
208
|
+
23
|
209
|
+
"made by worker #1"
|
210
|
+
23
|
211
|
+
"made by worker #2"
|
212
|
+
23
|
213
|
+
"made by worker #3"
|
214
|
+
23
|
215
|
+
...
|
216
|
+
```
|
217
|
+
|
218
|
+
# Status
|
219
|
+
|
220
|
+
What's implemented:
|
221
|
+
- Schema parsing/loading
|
222
|
+
- Message reading
|
223
|
+
- From byte string
|
224
|
+
- From file descriptor
|
225
|
+
- Message writing
|
226
|
+
- To byte string
|
227
|
+
- To file descriptor
|
228
|
+
- RPC
|
229
|
+
- loading InterfaceSchema and their methods
|
230
|
+
- RPC client
|
231
|
+
- RPC server
|
232
|
+
|
233
|
+
What's to come:
|
234
|
+
- More reading/writing mechanisms:
|
235
|
+
- Packing/unpacking
|
236
|
+
- Extensive test coverage
|
237
|
+
- Proper support for [JRuby][jruby]
|
238
|
+
- There is a known bug where the servers don't exits when pressing control-c. It only exits after
|
239
|
+
pressing control-c and then a request is made from a client.
|
240
|
+
|
241
|
+
[logo]: https://raw.github.com/cstrahan/capnp-ruby/master/media/captain_proto_small.png "Cap'n Proto"
|
242
|
+
[ruby]: http://www.ruby-lang.org/ "Ruby"
|
243
|
+
[capnp]: http://kentonv.github.io/capnproto/ "Cap'n Proto"
|
244
|
+
[jruby]: http://jruby.org/ "JRuby"
|
245
|
+
[libcapnp-install]: http://kentonv.github.io/capnproto/install.html "Installing Cap'n Proto"
|
246
|
+
[mit-license]: http://opensource.org/licenses/MIT "MIT License"
|
247
|
+
|
248
|
+
[travis-link]: https://travis-ci.org/cstrahan/capnp-ruby
|
249
|
+
[travis-badge]: https://travis-ci.org/cstrahan/capnp-ruby.png?branch=master
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'capn_proto/version'
|
2
|
+
GEMSPEC = eval(File.read('capn_proto.gemspec'))
|
3
|
+
|
4
|
+
require 'rubygems/package_task'
|
5
|
+
Gem::PackageTask.new(GEMSPEC) do |pkg|
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'rake/extensiontask'
|
9
|
+
Rake::ExtensionTask.new('capn_proto', GEMSPEC) do |ext|
|
10
|
+
ext.ext_dir = 'ext/capn_proto'
|
11
|
+
ext.lib_dir = 'lib/capn_proto'
|
12
|
+
ext.source_pattern = "*.{cc,h}"
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'rspec/core/rake_task'
|
16
|
+
RSpec::Core::RakeTask.new(:spec) do |config|
|
17
|
+
end
|
18
|
+
|
19
|
+
task :default => [:compile, :spec]
|
20
|
+
|
21
|
+
Rake::Task["clean"].clear
|
22
|
+
desc "Clean build artifacts"
|
23
|
+
task :clean do
|
24
|
+
rm_r "tmp" rescue nil
|
25
|
+
rm_r "pkg" rescue nil
|
26
|
+
rm "lib/capn_proto/capn_proto.bundle" rescue nil
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Tag commit, push to repo, then push to RubyGems"
|
30
|
+
task :release => [:clean, :compile, :spec, :gem] do
|
31
|
+
tag = "v#{CapnProto::VERSION}"
|
32
|
+
sh "git tag #{tag}"
|
33
|
+
sh "git push origin #{tag}"
|
34
|
+
sh "gem push pkg/capn_proto-#{CapnProto::VERSION}.gem"
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Open an irb console"
|
38
|
+
task :console do
|
39
|
+
$: << File.expand_path("../lib", __FILE__)
|
40
|
+
require 'irb'
|
41
|
+
require 'capn_proto'
|
42
|
+
ARGV.clear
|
43
|
+
IRB.start
|
44
|
+
end
|
data/capn_proto.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path('../lib/capn_proto/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'capn_proto-rpc'
|
5
|
+
s.license = 'MIT'
|
6
|
+
|
7
|
+
s.version = CapnProto::VERSION
|
8
|
+
s.required_ruby_version = '>= 2.0'
|
9
|
+
|
10
|
+
s.summary = "Cap'n Proto (libcapnp) bindings for Ruby."
|
11
|
+
|
12
|
+
s.description =
|
13
|
+
"This gem wraps the official C++ implementation of Cap'n Proto " \
|
14
|
+
"(libcapnp). " \
|
15
|
+
"From the Cap'n Proto documentation: " \
|
16
|
+
"\"Cap'n Proto is an insanely fast data interchange format and " \
|
17
|
+
"capability-based RPC system. Think JSON, except binary. " \
|
18
|
+
"Or think Protocol Buffers, except faster.\" " \
|
19
|
+
"This is a extended version of the original gem Capnproto which adds RPC support visit the homepage to view usage"
|
20
|
+
|
21
|
+
s.homepage = 'https://github.com/nemoNoboru/capnp-ruby'
|
22
|
+
|
23
|
+
s.authors = ['Charles Strahan','Felipe Vieira']
|
24
|
+
s.email = ['charles.c.strahan@gmail.com','felipetavres@gmail.com']
|
25
|
+
|
26
|
+
s.add_development_dependency 'rspec', '2.14.1'
|
27
|
+
s.add_development_dependency 'rake' , '~> 0'
|
28
|
+
s.add_development_dependency 'rake-compiler', '0.7.6'
|
29
|
+
|
30
|
+
s.add_development_dependency 'awesome_print', '~> 0'
|
31
|
+
s.add_development_dependency 'interactive_editor', '~> 0'
|
32
|
+
|
33
|
+
s.extensions = ['ext/capn_proto/extconf.rb']
|
34
|
+
s.require_paths = ['lib']
|
35
|
+
|
36
|
+
s.files = `git ls-files`.split("\n")
|
37
|
+
end
|
Binary file
|
@@ -0,0 +1,31 @@
|
|
1
|
+
@0x9eb32e19f86ee174;
|
2
|
+
|
3
|
+
struct Person {
|
4
|
+
id @0 :UInt32;
|
5
|
+
name @1 :Text;
|
6
|
+
email @2 :Text;
|
7
|
+
phones @3 :List(PhoneNumber);
|
8
|
+
|
9
|
+
struct PhoneNumber {
|
10
|
+
number @0 :Text;
|
11
|
+
type @1 :Type;
|
12
|
+
|
13
|
+
enum Type {
|
14
|
+
mobile @0;
|
15
|
+
home @1;
|
16
|
+
work @2;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
employment :union {
|
21
|
+
unemployed @4 :Void;
|
22
|
+
employer @5 :Text;
|
23
|
+
school @6 :Text;
|
24
|
+
selfEmployed @7 :Void;
|
25
|
+
# We assume that a person is only one of these.
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
struct AddressBook {
|
30
|
+
people @0 :List(Person);
|
31
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
from __future__ import print_function
|
3
|
+
import os
|
4
|
+
import capnp
|
5
|
+
|
6
|
+
this_dir = os.path.dirname(__file__)
|
7
|
+
out_path = os.path.join(this_dir, 'addressbook.bin')
|
8
|
+
addressbook = capnp.load(os.path.join(this_dir, 'addressbook.capnp'))
|
9
|
+
|
10
|
+
def writeAddressBook(file):
|
11
|
+
addresses = addressbook.AddressBook.newMessage()
|
12
|
+
people = addresses.init('people', 2)
|
13
|
+
|
14
|
+
alice = people[0]
|
15
|
+
alice.id = 123
|
16
|
+
alice.name = 'Alice'
|
17
|
+
alice.email = 'alice@example.com'
|
18
|
+
alicePhones = alice.init('phones', 1)
|
19
|
+
alicePhones[0].number = "555-1212"
|
20
|
+
alicePhones[0].type = 'mobile'
|
21
|
+
alice.employment.school = "MIT"
|
22
|
+
|
23
|
+
bob = people[1]
|
24
|
+
bob.id = 456
|
25
|
+
bob.name = 'Bob'
|
26
|
+
bob.email = 'bob@example.com'
|
27
|
+
bobPhones = bob.init('phones', 2)
|
28
|
+
bobPhones[0].number = "555-4567"
|
29
|
+
bobPhones[0].type = 'home'
|
30
|
+
bobPhones[1].number = "555-7654"
|
31
|
+
bobPhones[1].type = 'work'
|
32
|
+
bob.employment.unemployed = None
|
33
|
+
|
34
|
+
addresses.writeTo(file)
|
35
|
+
|
36
|
+
|
37
|
+
if __name__ == '__main__':
|
38
|
+
f = open(out_path, 'w')
|
39
|
+
writeAddressBook(f)
|