ruby-protocol-buffers 0.8.4 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +8 -0
- data/LICENSE +22 -20
- data/{README → README.md} +30 -35
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/bin/ruby-protoc +1 -0
- data/lib/protocol_buffers.rb +8 -0
- data/lib/protocol_buffers/compiler.rb +3 -0
- data/lib/protocol_buffers/compiler/file_descriptor_to_ruby.rb +9 -10
- data/lib/protocol_buffers/runtime/decoder.rb +1 -1
- data/lib/protocol_buffers/runtime/message.rb +4 -4
- data/spec/fields_spec.rb +1 -1
- data/spec/proto_files/top_level_enum.proto +10 -0
- data/spec/runtime_spec.rb +1 -1
- metadata +11 -13
- data/.gitignore +0 -11
data/Changelog.md
ADDED
data/LICENSE
CHANGED
@@ -1,22 +1,24 @@
|
|
1
|
-
Copyright (c) 2009
|
1
|
+
Copyright (c) 2009, Decho Corporation
|
2
|
+
All rights reserved.
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
* Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
* Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
* Neither the name of Decho Corporation nor the names of its contributors
|
12
|
+
may be used to endorse or promote products derived from this software
|
13
|
+
without specific prior written permission.
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
16
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
19
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/{README → README.md}
RENAMED
@@ -1,11 +1,11 @@
|
|
1
|
-
|
1
|
+
# Ruby Protocol Buffers
|
2
2
|
|
3
3
|
Protocol Buffers are a way of encoding structured data in an efficient yet
|
4
4
|
extensible format. Google uses Protocol Buffers for almost all of its internal
|
5
5
|
RPC protocols and file formats.
|
6
6
|
|
7
|
-
This library has two components: a compiler to turn
|
8
|
-
into Ruby modules (extension
|
7
|
+
This library has two components: a compiler to turn `.proto` definitions
|
8
|
+
into Ruby modules (extension `.pb.rb`), and a runtime to use protocol
|
9
9
|
buffers defined by these modules. The compiler relies on Google's C++ based
|
10
10
|
compiler (+protoc+) for much of the heavy lifting -- this has huge advantages in
|
11
11
|
ensuring compatibility and correctness.
|
@@ -19,9 +19,21 @@ Because this is a tool for generating code, the RDoc documentation is a bit
|
|
19
19
|
unusual. See the text in the ProtocolBuffers::Message class for details on what
|
20
20
|
code is generated.
|
21
21
|
|
22
|
-
|
22
|
+
## Installation
|
23
23
|
|
24
|
-
|
24
|
+
You'll need protoc version >= 2.2 (the Google Protocol Buffer compiler)
|
25
|
+
installed in the environment where you will be compiling protocol buffers. This
|
26
|
+
is only needed for compiling, you don't need it installed to use the generated
|
27
|
+
`.pb.rb` files. You do need this Ruby library installed to use the
|
28
|
+
`.pb.rb` files, for the runtime support.
|
29
|
+
|
30
|
+
If you use RubyGems, you can install via:
|
31
|
+
|
32
|
+
$ sudo gem install ruby-protocol-buffers
|
33
|
+
|
34
|
+
## Features
|
35
|
+
|
36
|
+
### Supported Features
|
25
37
|
|
26
38
|
* messages, enums, field types, all basic protobuf features
|
27
39
|
* packages
|
@@ -29,54 +41,37 @@ code is generated.
|
|
29
41
|
* nested types
|
30
42
|
* passing on unknown fields when re-serializing a message
|
31
43
|
|
32
|
-
|
44
|
+
### Unsupported Features
|
33
45
|
|
34
46
|
* extensions
|
35
47
|
* packed option (could be useful)
|
36
48
|
* accessing custom options
|
37
49
|
|
38
|
-
|
50
|
+
### Probably Never to be Supported
|
39
51
|
|
40
52
|
* RPC stubbing
|
41
53
|
* deprecated protocol features (e.g. groups)
|
42
54
|
* the unsupported options (java_*, optimize_for, message_set_wire_format, deprecated)
|
43
55
|
|
44
|
-
|
45
|
-
|
46
|
-
* not tested on Windows
|
47
|
-
* lots of polish still needed in APIs, docs, calling out to +protoc+, etc
|
56
|
+
## Simple Usage Example
|
48
57
|
|
49
|
-
|
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
|
50
65
|
|
51
|
-
|
52
|
-
$ bin/ruby-protoc test.proto
|
53
|
-
$ irb -I./lib -rtest.pb
|
54
|
-
> msg = Test::MyMessage.new(:myField => 'zomgkittenz')
|
55
|
-
=> #<Test::MyMessage myField="zomgkittenz">
|
56
|
-
> Test::MyMessage.parse(msg.to_s) == msg
|
57
|
-
=> true
|
58
|
-
|
59
|
-
== Authors
|
66
|
+
## Authors
|
60
67
|
|
61
68
|
Brian Palmer (http://github.com/codekitchen)
|
62
69
|
|
63
|
-
|
64
|
-
|
65
|
-
You'll need protoc version >= 2.2 (the Google Protocol Buffer compiler)
|
66
|
-
installed in the environment where you will be compiling protocol buffers. This
|
67
|
-
is only needed for compiling, you don't need it installed to use the generated
|
68
|
-
<tt>.pb.rb</tt> files. You do need this Ruby library installed to use the
|
69
|
-
<tt>.pb.rb</tt> files, for the runtime support.
|
70
|
-
|
71
|
-
If you use RubyGems, you can install via:
|
72
|
-
|
73
|
-
$ sudo gem install ruby-protocol-buffers
|
74
|
-
|
75
|
-
== Source
|
70
|
+
## Source
|
76
71
|
|
77
72
|
http://github.com/mozy/ruby-protocol-buffers
|
78
73
|
|
79
|
-
|
74
|
+
## License
|
80
75
|
|
81
76
|
See the LICENSE file included with the distribution for licensing and
|
82
77
|
copyright details.
|
data/Rakefile
CHANGED
@@ -18,6 +18,8 @@ begin
|
|
18
18
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
19
19
|
gem.required_ruby_version = ">=1.8.6"
|
20
20
|
gem.require_path = 'lib'
|
21
|
+
gem.extra_rdoc_files << "Changelog.md"
|
22
|
+
gem.files << "Changelog.md"
|
21
23
|
# disabled to avoid needing to compile a C extension just to boost
|
22
24
|
# performance. TODO: is there a way to tell gems to make the extension
|
23
25
|
# optional?
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.5
|
data/bin/ruby-protoc
CHANGED
@@ -33,6 +33,7 @@ require 'protocol_buffers'
|
|
33
33
|
require 'protocol_buffers/compiler'
|
34
34
|
|
35
35
|
protocfile = Tempfile.new("ruby-protoc")
|
36
|
+
protocfile.binmode
|
36
37
|
ProtocolBuffers::Compiler.compile(protocfile.path, filenames, :include_dirs => include_dirs)
|
37
38
|
descriptor_set = FileDescriptorSet.parse(protocfile)
|
38
39
|
protocfile.close(true)
|
data/lib/protocol_buffers.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
module ProtocolBuffers
|
2
2
|
VERSION = File.read(File.join(File.dirname(__FILE__), "..", "VERSION")).chomp
|
3
|
+
|
4
|
+
require 'stringio'
|
5
|
+
# for 1.9.2 compatibility
|
6
|
+
def self.bin_sio(*args)
|
7
|
+
sio = StringIO.new(*args)
|
8
|
+
sio.set_encoding('binary') if sio.respond_to?(:set_encoding)
|
9
|
+
sio
|
10
|
+
end
|
3
11
|
end
|
4
12
|
|
5
13
|
require 'protocol_buffers/runtime/message'
|
@@ -22,12 +22,14 @@ module ProtocolBuffers
|
|
22
22
|
require 'protocol_buffers/compiler/file_descriptor_to_ruby'
|
23
23
|
|
24
24
|
tempfile = Tempfile.new("protocol_buffers_spec")
|
25
|
+
tempfile.binmode
|
25
26
|
compile(tempfile.path, input_files, opts)
|
26
27
|
descriptor_set = FileDescriptorSet.parse(tempfile)
|
27
28
|
tempfile.close(true)
|
28
29
|
descriptor_set.file.each do |file|
|
29
30
|
parsed = FileDescriptorToRuby.new(file)
|
30
31
|
output = Tempfile.new("protocol_buffers_spec_parsed")
|
32
|
+
output.binmode
|
31
33
|
parsed.write(output)
|
32
34
|
output.flush
|
33
35
|
load output.path
|
@@ -39,6 +41,7 @@ module ProtocolBuffers
|
|
39
41
|
def self.compile_and_load_string(input, opts = {})
|
40
42
|
require 'tempfile'
|
41
43
|
tempfile = Tempfile.new("protocol_buffers_load_string")
|
44
|
+
tempfile.binmode
|
42
45
|
tempfile.write(input)
|
43
46
|
tempfile.flush
|
44
47
|
(opts[:include_dirs] ||= []) << File.dirname(tempfile.path)
|
@@ -39,10 +39,6 @@ HEADER
|
|
39
39
|
descriptor.message_type.each do |message|
|
40
40
|
dump_message(message)
|
41
41
|
end
|
42
|
-
|
43
|
-
descriptor.enum_type.each do |enum|
|
44
|
-
dump_enum(enum)
|
45
|
-
end
|
46
42
|
end
|
47
43
|
|
48
44
|
end
|
@@ -56,10 +52,16 @@ HEADER
|
|
56
52
|
messages.each do |message|
|
57
53
|
line %{class #{name([@package, message.name])} < ::ProtocolBuffers::Message; end}
|
58
54
|
end
|
59
|
-
|
60
|
-
|
55
|
+
|
56
|
+
if enums.empty?
|
57
|
+
line
|
58
|
+
else
|
59
|
+
line
|
60
|
+
line %{# enums}
|
61
|
+
enums.each do |enum|
|
62
|
+
dump_enum(enum)
|
63
|
+
end
|
61
64
|
end
|
62
|
-
line
|
63
65
|
end
|
64
66
|
|
65
67
|
def line(str = nil)
|
@@ -119,9 +121,6 @@ HEADER
|
|
119
121
|
line %{# nested messages} unless message.nested_type.empty?
|
120
122
|
message.nested_type.each { |inner| dump_message(inner) }
|
121
123
|
|
122
|
-
line %{# nested enums} unless message.enum_type.empty?
|
123
|
-
message.enum_type.each { |inner| dump_enum(inner) }
|
124
|
-
|
125
124
|
message.field.each do |field|
|
126
125
|
typename = field_typename(field)
|
127
126
|
fieldline = %{#{LABEL_MAPPING[field.label]} #{typename}, :#{field.name}, #{field.number}}
|
@@ -15,7 +15,7 @@ module ProtocolBuffers
|
|
15
15
|
field = fields[tag]
|
16
16
|
|
17
17
|
if field && wire_type != field.wire_type
|
18
|
-
raise(DecodeError, "incorrect wire type for tag: #{field.tag}")
|
18
|
+
raise(DecodeError, "incorrect wire type for tag: #{field.tag}, expected #{field.wire_type} but got #{wire_type}\n#{field.inspect}")
|
19
19
|
end
|
20
20
|
|
21
21
|
# replacing const lookups with hard-coded ints removed an entire 10%
|
@@ -58,7 +58,7 @@ module ProtocolBuffers
|
|
58
58
|
#
|
59
59
|
# === Singular Fields
|
60
60
|
#
|
61
|
-
# If you have a singular (optional or
|
61
|
+
# If you have a singular (optional or required) field +foo+ of any non-message
|
62
62
|
# type, you can manipulate the field +foo+ as if it were a regular object
|
63
63
|
# attribute. For example, if +foo+'s type is <tt>int32</tt>, you can say:
|
64
64
|
#
|
@@ -267,7 +267,7 @@ module ProtocolBuffers
|
|
267
267
|
|
268
268
|
# Serialize this Message to a String and return it.
|
269
269
|
def serialize_to_string
|
270
|
-
sio =
|
270
|
+
sio = ProtocolBuffers.bin_sio
|
271
271
|
serialize(sio)
|
272
272
|
return sio.string
|
273
273
|
end
|
@@ -285,7 +285,7 @@ module ProtocolBuffers
|
|
285
285
|
def parse(io_or_string)
|
286
286
|
io = io_or_string
|
287
287
|
if io.is_a?(String)
|
288
|
-
io =
|
288
|
+
io = ProtocolBuffers.bin_sio(io)
|
289
289
|
end
|
290
290
|
Decoder.decode(io, self)
|
291
291
|
return self
|
@@ -396,7 +396,7 @@ module ProtocolBuffers
|
|
396
396
|
end
|
397
397
|
|
398
398
|
def inspect
|
399
|
-
ret =
|
399
|
+
ret = ProtocolBuffers.bin_sio
|
400
400
|
ret << "#<#{self.class.name}"
|
401
401
|
fields.each do |tag, field|
|
402
402
|
ret << " #{field.name}=#{field.inspect_value(self.__send__(field.name))}"
|
data/spec/fields_spec.rb
CHANGED
@@ -26,7 +26,7 @@ describe ProtocolBuffers, "fields" do
|
|
26
26
|
it "properly encodes and decodes negative varints" do
|
27
27
|
val = -2082844800000000
|
28
28
|
str = "\200\300\313\274\236\265\246\374\377\001"
|
29
|
-
sio =
|
29
|
+
sio = ProtocolBuffers.bin_sio
|
30
30
|
ProtocolBuffers::Varint.encode(sio, val)
|
31
31
|
sio.string.should == str
|
32
32
|
sio.rewind
|
data/spec/runtime_spec.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-protocol-buffers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 55
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
8
|
+
- 5
|
9
|
+
version: 0.8.5
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Brian Palmer
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-12-19 00:00:00 -07:00
|
19
18
|
default_executable: ruby-protoc
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 13
|
30
28
|
segments:
|
31
29
|
- 1
|
32
30
|
- 2
|
@@ -41,13 +39,14 @@ executables:
|
|
41
39
|
extensions: []
|
42
40
|
|
43
41
|
extra_rdoc_files:
|
42
|
+
- Changelog.md
|
44
43
|
- LICENSE
|
45
|
-
- README
|
44
|
+
- README.md
|
46
45
|
files:
|
47
46
|
- .document
|
48
|
-
- .
|
47
|
+
- Changelog.md
|
49
48
|
- LICENSE
|
50
|
-
- README
|
49
|
+
- README.md
|
51
50
|
- Rakefile
|
52
51
|
- VERSION
|
53
52
|
- bin/ruby-protoc
|
@@ -81,6 +80,7 @@ files:
|
|
81
80
|
- spec/proto_files/featureful.proto
|
82
81
|
- spec/proto_files/no_package.proto
|
83
82
|
- spec/proto_files/simple.proto
|
83
|
+
- spec/proto_files/top_level_enum.proto
|
84
84
|
- spec/runtime_spec.rb
|
85
85
|
- spec/spec.opts
|
86
86
|
- spec/spec_helper.rb
|
@@ -89,8 +89,8 @@ homepage: http://github.com/mozy/ruby-protocol-buffers
|
|
89
89
|
licenses: []
|
90
90
|
|
91
91
|
post_install_message:
|
92
|
-
rdoc_options:
|
93
|
-
|
92
|
+
rdoc_options: []
|
93
|
+
|
94
94
|
require_paths:
|
95
95
|
- lib
|
96
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -98,7 +98,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
98
|
requirements:
|
99
99
|
- - ">="
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
hash: 59
|
102
101
|
segments:
|
103
102
|
- 1
|
104
103
|
- 8
|
@@ -109,7 +108,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
108
|
requirements:
|
110
109
|
- - ">="
|
111
110
|
- !ruby/object:Gem::Version
|
112
|
-
hash: 3
|
113
111
|
segments:
|
114
112
|
- 0
|
115
113
|
version: "0"
|
@@ -121,8 +119,8 @@ signing_key:
|
|
121
119
|
specification_version: 3
|
122
120
|
summary: Ruby compiler and runtime for the google protocol buffers library.
|
123
121
|
test_files:
|
122
|
+
- examples/json_protobuf.rb
|
124
123
|
- spec/compiler_spec.rb
|
125
124
|
- spec/fields_spec.rb
|
126
125
|
- spec/runtime_spec.rb
|
127
126
|
- spec/spec_helper.rb
|
128
|
-
- examples/json_protobuf.rb
|