protobuf 1.4.2 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Rakefile +7 -7
- data/bin/rpc_server +2 -188
- data/bin/rprotoc +44 -38
- data/examples/addressbook.pb.rb +2 -2
- data/ext/Makefile +11 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h +142 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h +318 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h +99 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h +103 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h +85 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h +167 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h +98 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h +72 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h +159 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h +170 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h +102 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +103 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h +118 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h +104 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h +2721 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h +303 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h +84 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h +121 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h +77 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h +108 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h +101 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h +72 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h +213 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h +109 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h +134 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h +121 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h +113 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h +120 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h +113 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h +64 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h +434 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h +73 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h +790 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h +156 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h +108 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h +93 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h +1367 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h +5223 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h +366 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h +136 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h +904 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h +424 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h +82 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h +1102 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h +64 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h +207 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h +54 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h +136 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h +313 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h +238 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h +357 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h +340 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/message.h +692 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h +239 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/package_info.h +64 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h +80 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h +1295 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/service.h +291 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h +1211 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h +220 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h +119 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h +123 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h +121 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h +457 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h +170 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/test_util.h +174 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h +101 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h +83 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h +98 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/text_format.h +285 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h +11915 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h +2895 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h +211 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h +56 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h +188 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h +151 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h +4752 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h +150 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h +816 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h +197 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h +403 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h +268 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h +304 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h +620 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h +774 -0
- data/ext/ruby_generator/RubyGenerator.cpp +435 -0
- data/ext/ruby_generator/RubyGenerator.h +180 -0
- data/ext/ruby_generator/extconf.rb +24 -0
- data/lib/protobuf.rb +55 -33
- data/lib/protobuf/cli.rb +176 -0
- data/lib/protobuf/common/logger.rb +11 -11
- data/lib/protobuf/{message/enum.rb → enum.rb} +0 -10
- data/lib/protobuf/evented.rb +22 -0
- data/lib/protobuf/field.rb +57 -0
- data/lib/protobuf/field/base_field.rb +210 -0
- data/lib/protobuf/field/bool_field.rb +24 -0
- data/lib/protobuf/field/bytes_field.rb +38 -0
- data/lib/protobuf/field/double_field.rb +19 -0
- data/lib/protobuf/field/enum_field.rb +58 -0
- data/lib/protobuf/field/extension_fields.rb +24 -0
- data/lib/protobuf/field/field_array.rb +55 -0
- data/lib/protobuf/field/fixed32_field.rb +19 -0
- data/lib/protobuf/field/fixed64_field.rb +22 -0
- data/lib/protobuf/field/float_field.rb +29 -0
- data/lib/protobuf/field/int32_field.rb +10 -0
- data/lib/protobuf/field/int64_field.rb +10 -0
- data/lib/protobuf/field/integer_field.rb +19 -0
- data/lib/protobuf/field/message_field.rb +51 -0
- data/lib/protobuf/field/sfixed32_field.rb +21 -0
- data/lib/protobuf/field/sfixed64_field.rb +24 -0
- data/lib/protobuf/field/signed_integer_field.rb +23 -0
- data/lib/protobuf/field/sint32_field.rb +10 -0
- data/lib/protobuf/field/sint64_field.rb +10 -0
- data/lib/protobuf/field/string_field.rb +14 -0
- data/lib/protobuf/field/uint32_field.rb +10 -0
- data/lib/protobuf/field/uint64_field.rb +10 -0
- data/lib/protobuf/field/varint_field.rb +63 -0
- data/lib/protobuf/message.rb +376 -0
- data/lib/protobuf/message/message.rb +1 -475
- data/lib/protobuf/rpc/buffer.rb +1 -1
- data/lib/protobuf/rpc/client.rb +26 -26
- data/lib/protobuf/rpc/connector.rb +15 -14
- data/lib/protobuf/rpc/connectors/eventmachine.rb +13 -13
- data/lib/protobuf/rpc/rpc.pb.rb +39 -28
- data/lib/protobuf/rpc/server.rb +7 -28
- data/lib/protobuf/rpc/servers/evented_runner.rb +15 -15
- data/lib/protobuf/rpc/servers/socket/server.rb +2 -1
- data/lib/protobuf/rpc/servers/socket_runner.rb +5 -6
- data/lib/protobuf/rpc/servers/zmq_runner.rb +4 -5
- data/lib/protobuf/socket.rb +22 -0
- data/lib/protobuf/version.rb +2 -1
- data/lib/protobuf/zmq.rb +21 -0
- data/proto/rpc.pb.rb +48 -0
- data/protobuf.gemspec +14 -6
- data/spec/benchmark/tasks.rb +42 -23
- data/spec/functional/evented_server_spec.rb +2 -0
- data/spec/functional/socket_server_spec.rb +22 -26
- data/spec/functional/zmq_server_spec.rb +22 -26
- data/spec/lib/protobuf/cli_spec.rb +182 -0
- data/spec/{unit → lib/protobuf}/common/logger_spec.rb +0 -0
- data/spec/{unit → lib/protobuf/message}/enum_spec.rb +0 -0
- data/spec/{unit → lib/protobuf/message}/message_spec.rb +0 -0
- data/spec/{unit → lib/protobuf}/rpc/client_spec.rb +6 -4
- data/spec/lib/protobuf/rpc/connector_spec.rb +41 -0
- data/spec/{unit → lib/protobuf}/rpc/connectors/base_spec.rb +18 -18
- data/spec/{unit → lib/protobuf}/rpc/connectors/common_spec.rb +20 -20
- data/spec/{unit → lib/protobuf}/rpc/connectors/socket_spec.rb +9 -8
- data/spec/{unit → lib/protobuf}/rpc/connectors/zmq_spec.rb +1 -1
- data/spec/{unit → lib/protobuf}/rpc/servers/evented_server_spec.rb +4 -4
- data/spec/{unit → lib/protobuf}/rpc/servers/socket_server_spec.rb +11 -23
- data/spec/{unit → lib/protobuf}/rpc/servers/zmq/broker_spec.rb +5 -0
- data/spec/{unit → lib/protobuf}/rpc/servers/zmq/server_spec.rb +5 -0
- data/spec/{unit → lib/protobuf}/rpc/servers/zmq/util_spec.rb +5 -0
- data/spec/{unit → lib/protobuf}/rpc/servers/zmq/worker_spec.rb +5 -0
- data/spec/{unit → lib/protobuf}/rpc/service_spec.rb +0 -0
- data/spec/proto/test.pb.rb +48 -25
- data/spec/spec_helper.rb +9 -15
- data/spec/support/all.rb +7 -0
- data/spec/{helper → support}/server.rb +5 -7
- data/spec/{helper → support}/silent_constants.rb +4 -0
- data/spec/support/test_app_file.rb +2 -0
- data/spec/{helper → support}/tolerance_matcher.rb +0 -0
- data/test/proto/types.pb.rb +1 -1
- data/test/test_addressbook.rb +1 -1
- data/test/test_enum_value.rb +1 -1
- data/test/test_standard_message.rb +1 -1
- metadata +243 -107
- data/lib/protobuf/common/util.rb +0 -59
- data/lib/protobuf/compiler/compiler.rb +0 -52
- data/lib/protobuf/compiler/nodes.rb +0 -323
- data/lib/protobuf/compiler/proto.y +0 -216
- data/lib/protobuf/compiler/proto2.ebnf +0 -79
- data/lib/protobuf/compiler/proto_parser.rb +0 -1425
- data/lib/protobuf/compiler/template/rpc_service_implementation.erb +0 -42
- data/lib/protobuf/compiler/visitors.rb +0 -282
- data/lib/protobuf/descriptor/descriptor.proto +0 -286
- data/lib/protobuf/descriptor/descriptor.rb +0 -55
- data/lib/protobuf/descriptor/descriptor_builder.rb +0 -143
- data/lib/protobuf/descriptor/descriptor_proto.rb +0 -138
- data/lib/protobuf/descriptor/enum_descriptor.rb +0 -33
- data/lib/protobuf/descriptor/field_descriptor.rb +0 -49
- data/lib/protobuf/descriptor/file_descriptor.rb +0 -37
- data/lib/protobuf/message/field.rb +0 -684
- data/lib/protobuf/message/protoable.rb +0 -38
- data/spec/helper/all.rb +0 -7
- data/spec/unit/common/util_spec.rb +0 -17
- data/spec/unit/rpc/connector_spec.rb +0 -31
- data/spec/unit/rpc/connectors/eventmachine_client_spec.rb +0 -32
- data/spec/unit/rpc/connectors/eventmachine_spec.rb +0 -0
- data/test/check_unbuild.rb +0 -30
- data/test/test_compiler.rb +0 -325
- data/test/test_descriptor.rb +0 -122
@@ -1,38 +0,0 @@
|
|
1
|
-
module Protobuf
|
2
|
-
module Protoable
|
3
|
-
def defined_filenames
|
4
|
-
@defined_filenames ||= []
|
5
|
-
end
|
6
|
-
|
7
|
-
def defined_in(filename)
|
8
|
-
path = File.expand_path(filename)
|
9
|
-
defined_filenames << path unless defined_filenames.include?(path)
|
10
|
-
end
|
11
|
-
|
12
|
-
def proto_filenames
|
13
|
-
defined_filenames.map do |filename|
|
14
|
-
retrieve_header(File.read(filename)).first
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def proto_contents
|
19
|
-
#TODO: temporary implementation because the result includes not only this message but also all messages
|
20
|
-
ret = {}
|
21
|
-
defined_filenames.each do |filename|
|
22
|
-
header = retrieve_header(File.read(filename))
|
23
|
-
ret[header.first] = header.last
|
24
|
-
end
|
25
|
-
ret
|
26
|
-
end
|
27
|
-
|
28
|
-
def retrieve_header(contents)
|
29
|
-
if contents =~ /### Generated by rprotoc\. DO NOT EDIT!\n### <proto file: (.*)>\n((# .*\n)+)/
|
30
|
-
proto_filename = $1
|
31
|
-
proto_contents = $2.gsub(/^# /, '')
|
32
|
-
[proto_filename, proto_contents]
|
33
|
-
else
|
34
|
-
[nil, nil]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/spec/helper/all.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Protobuf::Util do
|
4
|
-
|
5
|
-
describe '.underscore' do
|
6
|
-
it 'underscores constant name' do
|
7
|
-
Protobuf::Util.underscore("HelloMoto").should eq "hello_moto"
|
8
|
-
end
|
9
|
-
|
10
|
-
context 'when constant name has uppercased word' do
|
11
|
-
it 'keeps the uppercased word together' do
|
12
|
-
Protobuf::Util.underscore("UPPERCase").should eq "upper_case"
|
13
|
-
Protobuf::Util.underscore("MDXService").should eq "mdx_service"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Protobuf::Rpc::Connector do
|
4
|
-
|
5
|
-
describe '.connector_for_client' do
|
6
|
-
|
7
|
-
context 'when set to Socket connector' do
|
8
|
-
it 'returns a socket connector class reference' do
|
9
|
-
with_constants "Protobuf::ClientType" => "Socket" do
|
10
|
-
Protobuf::Rpc::Connector.connector_for_client.should eq(Protobuf::Rpc::Connectors::Socket)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'when set to non Socket Connector' do
|
16
|
-
it 'returns an eventmachine connector class reference' do
|
17
|
-
with_constants "Protobuf::ClientType" => "EventMachine" do
|
18
|
-
Protobuf::Rpc::Connector.connector_for_client.should eq Protobuf::Rpc::Connectors::EventMachine
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when connector type not given' do
|
24
|
-
it 'returns an eventmachine connector class reference' do
|
25
|
-
Protobuf::Rpc::Connector.connector_for_client.should eq Protobuf::Rpc::Connectors::EventMachine
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ::Protobuf::Rpc::Connectors::EMClient do
|
4
|
-
describe '#send_data' do
|
5
|
-
context 'when sending data errs' do
|
6
|
-
let(:buffer_double) do
|
7
|
-
bd = double(Protobuf::Rpc::Buffer)
|
8
|
-
bd.should_receive(:set_data)
|
9
|
-
bd
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'sets the error instance' do
|
13
|
-
buffer_double.should_receive(:write).and_raise(RuntimeError.new('Failure for testing'))
|
14
|
-
Protobuf::Rpc::Buffer.stub(:new).with(:read).and_return(Protobuf::Rpc::Buffer.new(:read))
|
15
|
-
Protobuf::Rpc::Buffer.stub(:new).with(:write).and_return(buffer_double)
|
16
|
-
error = nil
|
17
|
-
test_proc = Proc.new do
|
18
|
-
StubServer.new do |server|
|
19
|
-
client = ::Spec::Proto::TestService.client
|
20
|
-
client.find(:name => 'Test Name', :active => true) do |c|
|
21
|
-
c.on_failure do |f|
|
22
|
-
error = f
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
test_proc.call
|
28
|
-
error.should_not be_nil
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
File without changes
|
data/test/check_unbuild.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$:.push "#{File.dirname(__FILE__)}/../lib"
|
4
|
-
|
5
|
-
require 'test/unit'
|
6
|
-
require 'protobuf/descriptor/descriptor_builder'
|
7
|
-
require 'protobuf/descriptor/descriptor_proto'
|
8
|
-
|
9
|
-
class DescriptorTest < Test::Unit::TestCase
|
10
|
-
def test_unbuild
|
11
|
-
tutorial_proto = Google::Protobuf::FileDescriptorProto.new
|
12
|
-
tutorial_proto.parse_from_file 'person.bin'
|
13
|
-
Protobuf::Descriptor::DescriptorBuilder.build tutorial_proto
|
14
|
-
|
15
|
-
assert_nothing_raised {Tutorial::Person}
|
16
|
-
assert_nothing_raised {Tutorial::Person.new}
|
17
|
-
assert_equal(['age', 'email', 'id', 'name', 'phone'],
|
18
|
-
Tutorial::Person.fields.map{|tag, field| field.name}.sort)
|
19
|
-
|
20
|
-
assert_nothing_raised {Tutorial::Person::PhoneNumber}
|
21
|
-
assert_nothing_raised {Tutorial::Person::PhoneNumber.new}
|
22
|
-
assert_equal(['number', 'type'],
|
23
|
-
Tutorial::Person::PhoneNumber.fields.map{|tag, field| field.name}.sort)
|
24
|
-
|
25
|
-
assert_nothing_raised {Tutorial::Person::PhoneType}
|
26
|
-
assert_equal(0, Tutorial::Person::PhoneType::MOBILE)
|
27
|
-
assert_equal(1, Tutorial::Person::PhoneType::HOME)
|
28
|
-
assert_equal(2, Tutorial::Person::PhoneType::WORK)
|
29
|
-
end
|
30
|
-
end
|
data/test/test_compiler.rb
DELETED
@@ -1,325 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'protobuf/compiler/compiler'
|
3
|
-
|
4
|
-
class CompilerTest < Test::Unit::TestCase
|
5
|
-
# Issue 12: Parse error on float default value
|
6
|
-
def test_compile_float_default
|
7
|
-
assert_compile_proto(<<-EOS, 'test/proto/float_default.proto')
|
8
|
-
### Generated by rprotoc. DO NOT EDIT!
|
9
|
-
### <proto file: test/proto/float_default.proto>
|
10
|
-
# message M {
|
11
|
-
# optional float f = 1 [default = 4.2];
|
12
|
-
# optional float g = 2 [default = -4.2];
|
13
|
-
# optional float h = 3 [default = 4352];
|
14
|
-
# optional float i = 4 [default = 23145.2 ];
|
15
|
-
# optional float j = 5 [default = -5 ];
|
16
|
-
# optional float k = 6 [default = +23 ];
|
17
|
-
# optional float l = 7 [default = +23.42 ];
|
18
|
-
# }
|
19
|
-
#
|
20
|
-
|
21
|
-
require 'protobuf/message/message'
|
22
|
-
require 'protobuf/message/enum'
|
23
|
-
require 'protobuf/message/extend'
|
24
|
-
|
25
|
-
class M < ::Protobuf::Message
|
26
|
-
defined_in __FILE__
|
27
|
-
optional :float, :f, 1, :default => 4.2
|
28
|
-
optional :float, :g, 2, :default => -4.2
|
29
|
-
optional :float, :h, 3, :default => 4352
|
30
|
-
optional :float, :i, 4, :default => 23145.2
|
31
|
-
optional :float, :j, 5, :default => -5
|
32
|
-
optional :float, :k, 6, :default => 23
|
33
|
-
optional :float, :l, 7, :default => 23.42
|
34
|
-
end
|
35
|
-
EOS
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_create_message
|
39
|
-
assert_compile_proto(<<-EOS, 'test/proto/addressbook.proto')
|
40
|
-
### Generated by rprotoc. DO NOT EDIT!
|
41
|
-
### <proto file: test/proto/addressbook.proto>
|
42
|
-
# package tutorial;
|
43
|
-
#
|
44
|
-
# message Person {
|
45
|
-
# required string name = 1;
|
46
|
-
# required int32 id = 2;
|
47
|
-
# optional string email = 3;
|
48
|
-
#
|
49
|
-
# enum PhoneType {
|
50
|
-
# MOBILE = 0;
|
51
|
-
# HOME = 1;
|
52
|
-
# WORK = 2;
|
53
|
-
# }
|
54
|
-
#
|
55
|
-
# message PhoneNumber {
|
56
|
-
# required string number = 1;
|
57
|
-
# optional PhoneType type = 2 [default = HOME];
|
58
|
-
# }
|
59
|
-
#
|
60
|
-
# repeated PhoneNumber phone = 4;
|
61
|
-
# optional uint32 age = 5 [default = 20];
|
62
|
-
#
|
63
|
-
# extensions 100 to 200;
|
64
|
-
# }
|
65
|
-
#
|
66
|
-
# /*
|
67
|
-
# extend Person {
|
68
|
-
# optional int32 age = 100;
|
69
|
-
# }
|
70
|
-
# */
|
71
|
-
#
|
72
|
-
# message AddressBook {
|
73
|
-
# repeated Person person = 1;
|
74
|
-
# }
|
75
|
-
require 'protobuf/message/message'
|
76
|
-
require 'protobuf/message/enum'
|
77
|
-
require 'protobuf/message/extend'
|
78
|
-
|
79
|
-
module Tutorial
|
80
|
-
|
81
|
-
class Person < ::Protobuf::Message
|
82
|
-
defined_in __FILE__
|
83
|
-
required :string, :name, 1
|
84
|
-
required :int32, :id, 2
|
85
|
-
optional :string, :email, 3
|
86
|
-
|
87
|
-
class PhoneType < ::Protobuf::Enum
|
88
|
-
defined_in __FILE__
|
89
|
-
define :MOBILE, 0
|
90
|
-
define :HOME, 1
|
91
|
-
define :WORK, 2
|
92
|
-
end
|
93
|
-
|
94
|
-
class PhoneNumber < ::Protobuf::Message
|
95
|
-
defined_in __FILE__
|
96
|
-
required :string, :number, 1
|
97
|
-
optional :PhoneType, :type, 2, :default => :HOME
|
98
|
-
end
|
99
|
-
|
100
|
-
repeated :PhoneNumber, :phone, 4
|
101
|
-
optional :uint32, :age, 5, :default => 20
|
102
|
-
|
103
|
-
extensions 100..200
|
104
|
-
end
|
105
|
-
|
106
|
-
class AddressBook < ::Protobuf::Message
|
107
|
-
defined_in __FILE__
|
108
|
-
repeated :Person, :person, 1
|
109
|
-
end
|
110
|
-
end
|
111
|
-
EOS
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_create_nested_message
|
115
|
-
assert_compile_proto(<<-EOS, 'test/proto/nested.proto')
|
116
|
-
### Generated by rprotoc. DO NOT EDIT!
|
117
|
-
### <proto file: test/proto/nested.proto>
|
118
|
-
# package test.nested;
|
119
|
-
#
|
120
|
-
# message Foo {
|
121
|
-
# message Bar {
|
122
|
-
# }
|
123
|
-
# }
|
124
|
-
# message Baaz {
|
125
|
-
# optional Foo.Bar x = 1;
|
126
|
-
# }
|
127
|
-
|
128
|
-
require 'protobuf/message/message'
|
129
|
-
require 'protobuf/message/enum'
|
130
|
-
require 'protobuf/message/extend'
|
131
|
-
|
132
|
-
module Test
|
133
|
-
module Nested
|
134
|
-
class Foo < ::Protobuf::Message
|
135
|
-
defined_in __FILE__
|
136
|
-
class Bar < ::Protobuf::Message
|
137
|
-
defined_in __FILE__
|
138
|
-
end
|
139
|
-
end
|
140
|
-
class Baaz < ::Protobuf::Message
|
141
|
-
defined_in __FILE__
|
142
|
-
optional :'Foo::Bar', :x, 1
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
EOS
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_nested_message
|
150
|
-
file_contents = Protobuf::Compiler.new.create_message('test/proto/nested.proto', '.', '.', false)
|
151
|
-
assert_nothing_raised {Object.class_eval file_contents}
|
152
|
-
assert_raise(TypeError) {Test::Nested::Baaz.new.x = 1}
|
153
|
-
assert_nothing_raised {Test::Nested::Baaz.new.x = Test::Nested::Foo::Bar.new}
|
154
|
-
end
|
155
|
-
|
156
|
-
def test_create_rpc
|
157
|
-
file_contents = Protobuf::Compiler.new.create_rpc('test/proto/rpc.proto', '.', 'test/proto', false)
|
158
|
-
|
159
|
-
assert_source(<<-EOS, file_contents['test/proto/address_book_service.rb'])
|
160
|
-
require 'protobuf/rpc/server'
|
161
|
-
require 'protobuf/rpc/handler'
|
162
|
-
require 'test/proto/rpc.pb'
|
163
|
-
|
164
|
-
class Tutorial::SearchHandler < Protobuf::Rpc::Handler
|
165
|
-
request Tutorial::Person
|
166
|
-
response Tutorial::AddressBook
|
167
|
-
|
168
|
-
def self.process_request(request, response)
|
169
|
-
# TODO: edit this method
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
class Tutorial::AddHandler < Protobuf::Rpc::Handler
|
174
|
-
request Tutorial::Person
|
175
|
-
response Tutorial::Person
|
176
|
-
|
177
|
-
def self.process_request(request, response)
|
178
|
-
# TODO: edit this method
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
class Tutorial::AddressBookService < Protobuf::Rpc::Server
|
183
|
-
def setup_handlers
|
184
|
-
@handlers = {
|
185
|
-
:search => Tutorial::SearchHandler,
|
186
|
-
:add => Tutorial::AddHandler,
|
187
|
-
}
|
188
|
-
end
|
189
|
-
end
|
190
|
-
EOS
|
191
|
-
|
192
|
-
assert_source(<<-EOS, file_contents['test/proto/start_address_book_service'])
|
193
|
-
#!/usr/bin/env ruby
|
194
|
-
require 'address_book_service'
|
195
|
-
|
196
|
-
Tutorial::AddressBookService.new(:Port => 9999).start
|
197
|
-
EOS
|
198
|
-
|
199
|
-
assert_source(<<-EOS, file_contents['test/proto/client_search.rb'])
|
200
|
-
#!/usr/bin/env ruby
|
201
|
-
require 'protobuf/rpc/client'
|
202
|
-
require 'test/proto/rpc.pb'
|
203
|
-
|
204
|
-
# build request
|
205
|
-
request = Tutorial::Person.new
|
206
|
-
# TODO: setup a request
|
207
|
-
raise StandardError, 'setup a request'
|
208
|
-
|
209
|
-
# create blunk response
|
210
|
-
response = Tutorial::AddressBook.new
|
211
|
-
|
212
|
-
# execute rpc
|
213
|
-
Protobuf::Rpc::Client.new('localhost', 9999).call :search, request, response
|
214
|
-
|
215
|
-
# show response
|
216
|
-
puts response
|
217
|
-
EOS
|
218
|
-
|
219
|
-
assert_source(<<-EOS, file_contents['test/proto/client_add.rb'])
|
220
|
-
#!/usr/bin/env ruby
|
221
|
-
require 'protobuf/rpc/client'
|
222
|
-
require 'test/proto/rpc.pb'
|
223
|
-
|
224
|
-
# build request
|
225
|
-
request = Tutorial::Person.new
|
226
|
-
# TODO: setup a request
|
227
|
-
raise StandardError, 'setup a request'
|
228
|
-
|
229
|
-
# create blunk response
|
230
|
-
response = Tutorial::Person.new
|
231
|
-
|
232
|
-
# execute rpc
|
233
|
-
Protobuf::Rpc::Client.new('localhost', 9999).call :add, request, response
|
234
|
-
|
235
|
-
# show response
|
236
|
-
puts response
|
237
|
-
EOS
|
238
|
-
end
|
239
|
-
|
240
|
-
def test_create_descriptor
|
241
|
-
proto_path = 'test/proto/addressbook.proto'
|
242
|
-
visitor = Protobuf::Visitor::CreateDescriptorVisitor.new(proto_path)
|
243
|
-
File.open(proto_path) do |file|
|
244
|
-
visitor.visit Protobuf::ProtoParser.new.parse(file)
|
245
|
-
end
|
246
|
-
file_descriptor = visitor.file_descriptor
|
247
|
-
assert_equal(proto_path, file_descriptor.name)
|
248
|
-
assert_equal('tutorial', file_descriptor.package)
|
249
|
-
|
250
|
-
person_descriptor = file_descriptor.message_type[0]
|
251
|
-
assert_equal('Person', person_descriptor.name)
|
252
|
-
assert_equal([:name, :id, :email, :phone, :age].size, person_descriptor.field.size)
|
253
|
-
|
254
|
-
name_field_descriptor = person_descriptor.field.find {|d| d.name == 'name'}
|
255
|
-
assert_equal(1, name_field_descriptor.number)
|
256
|
-
assert_equal(Google::Protobuf::FieldDescriptorProto::Type::TYPE_STRING, name_field_descriptor.type)
|
257
|
-
assert_equal(Google::Protobuf::FieldDescriptorProto::Label::LABEL_REQUIRED, name_field_descriptor.label)
|
258
|
-
assert_equal('string', name_field_descriptor.type_name)
|
259
|
-
|
260
|
-
phone_field_descriptor = person_descriptor.field.find {|d| d.name == 'phone'}
|
261
|
-
assert_equal(4, phone_field_descriptor.number)
|
262
|
-
assert_equal(0, phone_field_descriptor.type) #TODO: is this right?
|
263
|
-
assert_equal(Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED, phone_field_descriptor.label)
|
264
|
-
assert_equal('PhoneNumber', phone_field_descriptor.type_name)
|
265
|
-
|
266
|
-
age_field_descriptor = person_descriptor.field.find {|d| d.name == 'age'}
|
267
|
-
assert_equal(5, age_field_descriptor.number)
|
268
|
-
assert_equal(Google::Protobuf::FieldDescriptorProto::Type::TYPE_UINT32, age_field_descriptor.type)
|
269
|
-
assert_equal(Google::Protobuf::FieldDescriptorProto::Label::LABEL_OPTIONAL, age_field_descriptor.label)
|
270
|
-
assert_equal('uint32', age_field_descriptor.type_name)
|
271
|
-
assert_equal('20', age_field_descriptor.default_value)
|
272
|
-
|
273
|
-
phone_type_descriptor = person_descriptor.enum_type.first
|
274
|
-
assert_equal('PhoneType', phone_type_descriptor.name)
|
275
|
-
assert_equal(3, phone_type_descriptor.value.size)
|
276
|
-
|
277
|
-
phone_type_home_descriptor = phone_type_descriptor.value.find {|d| d.name == 'HOME'}
|
278
|
-
assert_equal('HOME', phone_type_home_descriptor.name)
|
279
|
-
assert_equal(1, phone_type_home_descriptor.number)
|
280
|
-
|
281
|
-
extensions_descriptor = person_descriptor.extension_range.first
|
282
|
-
assert_equal(100, extensions_descriptor.start)
|
283
|
-
assert_equal(200, extensions_descriptor.end)
|
284
|
-
|
285
|
-
phone_number_descriptor = person_descriptor.nested_type.first
|
286
|
-
assert_equal('PhoneNumber', phone_number_descriptor.name)
|
287
|
-
assert_equal([:number, :type].size, phone_number_descriptor.field.size)
|
288
|
-
|
289
|
-
#TODO: test extend
|
290
|
-
#extend_person_descriptor = ??
|
291
|
-
#assert_equal extend_person_descriptor
|
292
|
-
|
293
|
-
addressbook_descriptor = file_descriptor.message_type[1]
|
294
|
-
assert_equal('AddressBook', addressbook_descriptor.name)
|
295
|
-
end
|
296
|
-
|
297
|
-
def test_collision
|
298
|
-
assert_raise(Protobuf::TagCollisionError) do require 'test/proto/collision.pb' end
|
299
|
-
assert_raise(Protobuf::TagCollisionError) do
|
300
|
-
Protobuf::Compiler.new.create_message('test/proto/collision.proto', '.', '.', false)
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
def test_ext_collision
|
305
|
-
assert_raise(Protobuf::TagCollisionError) do require 'test/proto/ext_collision.pb' end
|
306
|
-
assert_raise(Protobuf::TagCollisionError) do
|
307
|
-
Protobuf::Compiler.new.create_message('test/proto/ext_collision.proto', '.', '.', false)
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
def test_ext_range
|
312
|
-
assert_raise(RangeError) do require 'test/proto/ext_range.pb' end
|
313
|
-
assert_raise(RangeError) do
|
314
|
-
Protobuf::Compiler.new.create_message('test/proto/ext_range.proto', '.', '.', false)
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
def assert_compile_proto(ideal, filename)
|
319
|
-
assert_equal(ideal.gsub(/^\s*\n/, '').strip, Protobuf::Compiler.new.create_message(filename, '.', '.', false).gsub(/^\s*\n/, '').strip)
|
320
|
-
end
|
321
|
-
|
322
|
-
def assert_source(ideal, real)
|
323
|
-
assert_equal(ideal.strip.gsub(/^\s*\n/, '').gsub(/\s+\n/, "\n"), real.strip.gsub(/^\s*\n/, '').gsub(/\s+\n/, "\n"))
|
324
|
-
end
|
325
|
-
end
|