ruby-protocol-buffers 1.2.3.beta2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +110 -24
- data/VERSION +1 -1
- data/ruby-protocol-buffers.gemspec +2 -1
- metadata +28 -12
data/README.md
CHANGED
@@ -6,14 +6,16 @@ RPC protocols and file formats.
|
|
6
6
|
|
7
7
|
This library has two components: a compiler to turn `.proto` definitions
|
8
8
|
into Ruby modules (extension `.pb.rb`), and a runtime to use protocol
|
9
|
-
buffers defined by these modules.
|
10
|
-
compiler (+protoc+) for much of the heavy lifting -- this has huge advantages in
|
11
|
-
ensuring compatibility and correctness.
|
9
|
+
buffers defined by these modules.
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
The compiler relies on Google's C++ based compiler (`protoc`) for much
|
12
|
+
of the heavy lifting -- this has huge advantages in ensuring
|
13
|
+
compatibility and correctness. If you don't need cross-language
|
14
|
+
interoperability you can create Message classes directly in ruby,
|
15
|
+
in which case `protoc` is not needed. See "Writing Message Classes
|
16
|
+
Directly" below.
|
17
|
+
|
18
|
+
This library is heavily optimized for encoding and decoding speed.
|
17
19
|
|
18
20
|
Because this is a tool for generating code, the RDoc documentation is a bit
|
19
21
|
unusual. See the text in the ProtocolBuffers::Message class for details on what
|
@@ -21,15 +23,109 @@ code is generated.
|
|
21
23
|
|
22
24
|
## Installation
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
$ gem install ruby-protocol-buffers
|
27
|
+
|
28
|
+
If you want to compile .proto files to ruby, you'll need `protoc` version >= 2.2 (the Google Protocol Buffer compiler)
|
29
|
+
installed in the environment where you will be compiling them.
|
30
|
+
You do not need `protoc` installed to use the generated `.pb.rb` files.
|
31
|
+
|
32
|
+
## Example
|
33
|
+
|
34
|
+
Given the file test.proto:
|
35
|
+
|
36
|
+
```
|
37
|
+
package Test;
|
38
|
+
|
39
|
+
message MyMessage
|
40
|
+
{
|
41
|
+
optional string myField = 1;
|
42
|
+
}
|
43
|
+
```
|
44
|
+
|
45
|
+
Compile it to ruby using the command:
|
46
|
+
|
47
|
+
$ ruby-protoc test.proto
|
48
|
+
|
49
|
+
Then it can be used from ruby code:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
require 'test.pb'
|
53
|
+
msg = Test::MyMessage.new(:myField => 'zomgkittenz')
|
54
|
+
open("test_msg", "wb") do |f|
|
55
|
+
msg.serialize(f)
|
56
|
+
end
|
57
|
+
encoded = msg.serialize_to_string # or msg.to_s
|
58
|
+
Test::MyMessage.parse(encoded) == msg # true
|
59
|
+
```
|
60
|
+
|
61
|
+
## Writing Message Classes Directly
|
62
|
+
|
63
|
+
Protocol Buffer definitions are often shared between applications
|
64
|
+
written in different programming languages, and so are normally defined
|
65
|
+
in .proto files and translated to ruby using the `ruby-protoc` binary.
|
66
|
+
|
67
|
+
However, it's quite simple to write ProtocolBuffers::Message classes
|
68
|
+
directly when a .proto file isn't needed.
|
29
69
|
|
30
|
-
|
70
|
+
```ruby
|
71
|
+
require 'protocol_buffers'
|
31
72
|
|
32
|
-
|
73
|
+
class User < ProtocolBuffers::Message
|
74
|
+
required :string, :name, 1
|
75
|
+
required :string, :email, 2
|
76
|
+
optional :int32, :logins, 3
|
77
|
+
end
|
78
|
+
|
79
|
+
class Group < ProtocolBuffers::Message
|
80
|
+
repeated User, :users, 1
|
81
|
+
repeated Group, :subgroups, 2
|
82
|
+
|
83
|
+
module GroupType
|
84
|
+
include ProtocolBuffers::Enum
|
85
|
+
Study = 1
|
86
|
+
Play = 2
|
87
|
+
end
|
88
|
+
|
89
|
+
optional GroupType, :group_type, 3
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
This code is essentially equivalent to the code `ruby-protoc` will
|
94
|
+
generate if given this .proto file:
|
95
|
+
|
96
|
+
```
|
97
|
+
message User
|
98
|
+
{
|
99
|
+
required string name = 1;
|
100
|
+
required string email = 2;
|
101
|
+
optional int32 logins = 3;
|
102
|
+
}
|
103
|
+
|
104
|
+
message Group
|
105
|
+
{
|
106
|
+
repeated User users = 1;
|
107
|
+
repeated Group subgroups = 2;
|
108
|
+
|
109
|
+
enum GroupType {
|
110
|
+
Study = 1;
|
111
|
+
Play = 2;
|
112
|
+
}
|
113
|
+
|
114
|
+
optional GroupType group_type = 3;
|
115
|
+
}
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
Using a hand-written Message subclass is the same as using a Message
|
120
|
+
class generated by `ruby-protoc`.
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
group = Group.new(:group_type => Group::GroupType::Play)
|
124
|
+
group.users << User.new(:name => 'test user', :email => 'test@example.com')
|
125
|
+
open("group1.test", "wb") do |f|
|
126
|
+
group.serialize(f)
|
127
|
+
end
|
128
|
+
```
|
33
129
|
|
34
130
|
## Features
|
35
131
|
|
@@ -53,16 +149,6 @@ If you use RubyGems, you can install via:
|
|
53
149
|
* deprecated protocol features (e.g. groups)
|
54
150
|
* the unsupported options (java_*, optimize_for, message_set_wire_format, deprecated)
|
55
151
|
|
56
|
-
## Simple Usage Example
|
57
|
-
|
58
|
-
$ echo "package Test; message MyMessage { optional string myField = 1; }" > test.proto
|
59
|
-
$ bin/ruby-protoc test.proto
|
60
|
-
$ irb -I./lib -rtest.pb
|
61
|
-
> msg = Test::MyMessage.new(:myField => 'zomgkittenz')
|
62
|
-
=> #<Test::MyMessage myField="zomgkittenz">
|
63
|
-
> Test::MyMessage.parse(msg.to_s) == msg
|
64
|
-
=> true
|
65
|
-
|
66
152
|
## Authors
|
67
153
|
|
68
154
|
Brian Palmer (http://github.com/codekitchen)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
@@ -18,9 +18,10 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.extra_rdoc_files << "Changelog.md"
|
20
20
|
|
21
|
-
s.add_development_dependency "rspec", "~> 2.5"
|
22
21
|
s.add_development_dependency "autotest-standalone"
|
23
22
|
s.add_development_dependency "autotest-growl"
|
23
|
+
s.add_development_dependency "rake"
|
24
24
|
s.add_development_dependency "rcov"
|
25
|
+
s.add_development_dependency "rspec", "~> 2.5"
|
25
26
|
s.add_development_dependency "yard"
|
26
27
|
end
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-protocol-buffers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.3.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Brian Palmer
|
@@ -11,26 +11,26 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2013-01-18 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
|
-
name:
|
17
|
+
name: autotest-standalone
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
|
-
- -
|
21
|
+
- - ! '>='
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: '
|
23
|
+
version: '0'
|
24
24
|
type: :development
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
none: false
|
28
28
|
requirements:
|
29
|
-
- -
|
29
|
+
- - ! '>='
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version: '
|
31
|
+
version: '0'
|
32
32
|
- !ruby/object:Gem::Dependency
|
33
|
-
name: autotest-
|
33
|
+
name: autotest-growl
|
34
34
|
requirement: !ruby/object:Gem::Requirement
|
35
35
|
none: false
|
36
36
|
requirements:
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
49
|
+
name: rake
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
@@ -77,6 +77,22 @@ dependencies:
|
|
77
77
|
- - ! '>='
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '0'
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rspec
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '2.5'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ~>
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '2.5'
|
80
96
|
- !ruby/object:Gem::Dependency
|
81
97
|
name: yard
|
82
98
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,9 +182,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
166
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
183
|
none: false
|
168
184
|
requirements:
|
169
|
-
- - ! '
|
185
|
+
- - ! '>='
|
170
186
|
- !ruby/object:Gem::Version
|
171
|
-
version:
|
187
|
+
version: '0'
|
172
188
|
requirements: []
|
173
189
|
rubyforge_project:
|
174
190
|
rubygems_version: 1.8.23
|