protobuf 2.8.13 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +84 -5
- data/CONTRIBUTING.md +3 -3
- data/Rakefile +46 -7
- data/lib/protobuf/cli.rb +2 -20
- data/lib/protobuf/decoder.rb +74 -0
- data/lib/protobuf/deprecator.rb +42 -0
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +17 -16
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +86 -85
- data/lib/protobuf/encoder.rb +62 -0
- data/lib/protobuf/enum.rb +298 -37
- data/lib/protobuf/field/base_field.rb +41 -27
- data/lib/protobuf/field/bool_field.rb +22 -4
- data/lib/protobuf/field/bytes_field.rb +36 -15
- data/lib/protobuf/field/double_field.rb +10 -3
- data/lib/protobuf/field/enum_field.rb +21 -18
- data/lib/protobuf/field/field_array.rb +26 -16
- data/lib/protobuf/field/fixed32_field.rb +10 -4
- data/lib/protobuf/field/fixed64_field.rb +10 -3
- data/lib/protobuf/field/float_field.rb +18 -5
- data/lib/protobuf/field/int32_field.rb +14 -4
- data/lib/protobuf/field/int64_field.rb +14 -4
- data/lib/protobuf/field/integer_field.rb +9 -4
- data/lib/protobuf/field/message_field.rb +16 -7
- data/lib/protobuf/field/sfixed32_field.rb +10 -3
- data/lib/protobuf/field/sfixed64_field.rb +12 -7
- data/lib/protobuf/field/signed_integer_field.rb +7 -0
- data/lib/protobuf/field/sint32_field.rb +14 -4
- data/lib/protobuf/field/sint64_field.rb +14 -4
- data/lib/protobuf/field/string_field.rb +11 -1
- data/lib/protobuf/field/uint32_field.rb +14 -4
- data/lib/protobuf/field/uint64_field.rb +14 -4
- data/lib/protobuf/field/varint_field.rb +11 -9
- data/lib/protobuf/field.rb +42 -25
- data/lib/protobuf/generators/enum_generator.rb +12 -1
- data/lib/protobuf/generators/field_generator.rb +1 -1
- data/lib/protobuf/lifecycle.rb +3 -4
- data/lib/protobuf/message/fields.rb +122 -0
- data/lib/protobuf/message/serialization.rb +84 -0
- data/lib/protobuf/message.rb +21 -221
- data/lib/protobuf/optionable.rb +23 -0
- data/lib/protobuf/rpc/client.rb +2 -4
- data/lib/protobuf/rpc/connector.rb +0 -2
- data/lib/protobuf/rpc/connectors/common.rb +2 -2
- data/lib/protobuf/rpc/dynamic_discovery.pb.rb +14 -16
- data/lib/protobuf/rpc/env.rb +58 -0
- data/lib/protobuf/rpc/error.rb +8 -5
- data/lib/protobuf/rpc/middleware/exception_handler.rb +36 -0
- data/lib/protobuf/rpc/middleware/logger.rb +91 -0
- data/lib/protobuf/rpc/middleware/request_decoder.rb +83 -0
- data/lib/protobuf/rpc/middleware/response_encoder.rb +88 -0
- data/lib/protobuf/rpc/middleware/runner.rb +18 -0
- data/lib/protobuf/rpc/middleware.rb +25 -0
- data/lib/protobuf/rpc/rpc.pb.rb +15 -16
- data/lib/protobuf/rpc/server.rb +14 -64
- data/lib/protobuf/rpc/servers/socket/server.rb +0 -2
- data/lib/protobuf/rpc/servers/socket/worker.rb +11 -15
- data/lib/protobuf/rpc/servers/zmq/util.rb +4 -1
- data/lib/protobuf/rpc/servers/zmq/worker.rb +5 -13
- data/lib/protobuf/rpc/servers/zmq_runner.rb +1 -1
- data/lib/protobuf/rpc/service.rb +38 -72
- data/lib/protobuf/rpc/service_dispatcher.rb +20 -108
- data/lib/protobuf/version.rb +1 -2
- data/lib/protobuf.rb +5 -13
- data/protobuf.gemspec +5 -5
- data/spec/benchmark/tasks.rb +2 -77
- data/spec/functional/zmq_server_spec.rb +13 -21
- data/spec/lib/protobuf/cli_spec.rb +5 -43
- data/spec/lib/protobuf/enum_spec.rb +194 -61
- data/spec/lib/protobuf/field_spec.rb +194 -0
- data/spec/lib/protobuf/generators/enum_generator_spec.rb +24 -1
- data/spec/lib/protobuf/generators/field_generator_spec.rb +6 -6
- data/spec/lib/protobuf/message_spec.rb +52 -70
- data/spec/lib/protobuf/optionable_spec.rb +46 -0
- data/spec/lib/protobuf/rpc/client_spec.rb +1 -93
- data/spec/lib/protobuf/rpc/connector_spec.rb +1 -7
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +8 -0
- data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +62 -0
- data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +49 -0
- data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +115 -0
- data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +75 -0
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +0 -6
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +10 -0
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +30 -105
- data/spec/lib/protobuf/rpc/service_filters_spec.rb +4 -4
- data/spec/lib/protobuf/rpc/service_spec.rb +20 -24
- data/spec/lib/protobuf_spec.rb +3 -3
- data/spec/spec_helper.rb +5 -4
- data/spec/support/packed_field.rb +15 -14
- data/spec/support/server.rb +4 -21
- data/spec/support/test/defaults.pb.rb +4 -4
- data/spec/support/test/enum.pb.rb +13 -1
- data/spec/support/test/enum.proto +15 -0
- data/spec/support/test/extended.pb.rb +1 -1
- data/spec/support/test/google_unittest.pb.rb +239 -241
- data/spec/support/test/google_unittest_import.pb.rb +2 -2
- data/spec/support/test/multi_field_extensions.pb.rb +2 -2
- data/spec/support/test/resource.pb.rb +19 -18
- data/spec/support/test/resource.proto +1 -0
- data/spec/support/test/resource_service.rb +5 -0
- metadata +78 -57
- data/bin/rprotoc +0 -8
- data/lib/protobuf/enum_value.rb +0 -85
- data/lib/protobuf/evented.rb +0 -37
- data/lib/protobuf/ext/eventmachine.rb +0 -14
- data/lib/protobuf/field/extension_fields.rb +0 -32
- data/lib/protobuf/message/decoder.rb +0 -72
- data/lib/protobuf/message/message.rb +0 -1
- data/lib/protobuf/rpc/connectors/em_client.rb +0 -84
- data/lib/protobuf/rpc/connectors/eventmachine.rb +0 -87
- data/lib/protobuf/rpc/servers/evented/server.rb +0 -36
- data/lib/protobuf/rpc/servers/evented_runner.rb +0 -31
- data/spec/functional/embedded_service_spec.rb +0 -7
- data/spec/functional/evented_server_spec.rb +0 -64
- data/spec/lib/protobuf/enum_value_spec.rb +0 -29
- data/spec/lib/protobuf/rpc/servers/evented_server_spec.rb +0 -19
data/spec/support/server.rb
CHANGED
@@ -12,7 +12,7 @@ Thread.abort_on_exception = true
|
|
12
12
|
|
13
13
|
module StubProtobufServerFactory
|
14
14
|
def self.build(delay)
|
15
|
-
new_server = Class.new(Protobuf::Rpc::
|
15
|
+
new_server = Class.new(Protobuf::Rpc::Socket::Server) do
|
16
16
|
def self.sleep_interval
|
17
17
|
@sleep_interval
|
18
18
|
end
|
@@ -43,7 +43,7 @@ class StubServer
|
|
43
43
|
:port => 9399,
|
44
44
|
:worker_port => 9400,
|
45
45
|
:delay => 0,
|
46
|
-
:server => Protobuf::Rpc::
|
46
|
+
:server => Protobuf::Rpc::Socket::Server }.merge(options))
|
47
47
|
|
48
48
|
start
|
49
49
|
yield self
|
@@ -53,38 +53,23 @@ class StubServer
|
|
53
53
|
|
54
54
|
def start
|
55
55
|
case
|
56
|
-
when @options.server == Protobuf::Rpc::Evented::Server
|
57
|
-
start_em_server
|
58
56
|
when @options.server == Protobuf::Rpc::Zmq::Server
|
59
57
|
start_zmq_server
|
60
58
|
else
|
61
59
|
start_socket_server
|
62
60
|
end
|
63
61
|
log_debug { sign_message("Server started #{@options.host}:#{@options.port}") }
|
64
|
-
rescue => ex
|
65
|
-
if ex =~ /no acceptor/ # Means EM didn't shutdown in the next_tick yet
|
66
|
-
stop
|
67
|
-
retry
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def start_em_server
|
72
|
-
@server_handle = EventMachine.start_server(
|
73
|
-
@options.host,
|
74
|
-
@options.port,
|
75
|
-
StubProtobufServerFactory.build(@options.delay)
|
76
|
-
)
|
77
62
|
end
|
78
63
|
|
79
64
|
def start_socket_server
|
80
|
-
@sock_runner = ::Protobuf::Rpc::SocketRunner.new(
|
65
|
+
@sock_runner = ::Protobuf::Rpc::SocketRunner.new(options)
|
81
66
|
@sock_thread = Thread.new(@sock_runner) { |runner| runner.run }
|
82
67
|
@sock_thread.abort_on_exception = true # Set for testing purposes
|
83
68
|
Thread.pass until @sock_runner.running?
|
84
69
|
end
|
85
70
|
|
86
71
|
def start_zmq_server
|
87
|
-
@
|
72
|
+
@zmq_runner = ::Protobuf::Rpc::ZmqRunner.new(options)
|
88
73
|
@zmq_thread = Thread.new(@zmq_runner) { |runner| runner.run }
|
89
74
|
@zmq_thread.abort_on_exception = true # Set for testing purposes
|
90
75
|
Thread.pass until @zmq_runner.running?
|
@@ -92,8 +77,6 @@ class StubServer
|
|
92
77
|
|
93
78
|
def stop
|
94
79
|
case
|
95
|
-
when @options.server == Protobuf::Rpc::Evented::Server then
|
96
|
-
EventMachine.stop_server(@server_handle) if @server_handle
|
97
80
|
when @options.server == Protobuf::Rpc::Zmq::Server then
|
98
81
|
@zmq_runner.try :stop
|
99
82
|
@zmq_thread.join if @zmq_thread
|
@@ -15,10 +15,10 @@ module Test
|
|
15
15
|
# Message Fields
|
16
16
|
#
|
17
17
|
class Defaults
|
18
|
-
optional
|
19
|
-
optional
|
20
|
-
optional
|
21
|
-
optional
|
18
|
+
optional :bytes, :escaped_bytes, 1, :default => "\000\001\007\010\014\n\r\t\013\\\\'\"\376"
|
19
|
+
optional :double, :infinity_default, 2, :default => ::Float::INFINITY
|
20
|
+
optional :float, :neg_infinity_default, 3, :default => -::Float::INFINITY
|
21
|
+
optional :double, :nan_default, 4, :default => ::Float::NAN
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
@@ -19,6 +19,15 @@ module Test
|
|
19
19
|
define :TWO, 2
|
20
20
|
end
|
21
21
|
|
22
|
+
class AliasedEnum < ::Protobuf::Enum
|
23
|
+
set_option :allow_alias
|
24
|
+
|
25
|
+
define :THREE, 3
|
26
|
+
define :TRES, 3
|
27
|
+
define :FOUR, 4
|
28
|
+
define :CUATRO, 4
|
29
|
+
end
|
30
|
+
|
22
31
|
|
23
32
|
##
|
24
33
|
# Message Classes
|
@@ -33,6 +42,9 @@ module Test
|
|
33
42
|
optional ::Test::EnumTestType, :non_default_enum, 1
|
34
43
|
optional ::Test::EnumTestType, :default_enum, 2, :default => ::Test::EnumTestType::ONE
|
35
44
|
repeated ::Test::EnumTestType, :repeated_enums, 3
|
45
|
+
optional ::Test::AliasedEnum, :alias_non_default_enum, 4
|
46
|
+
optional ::Test::AliasedEnum, :alias_default_enum, 5, :default => ::Test::AliasedEnum::CUATRO
|
47
|
+
repeated ::Test::AliasedEnum, :alias_repeated_enums, 6
|
36
48
|
end
|
37
49
|
|
38
50
|
|
@@ -40,7 +52,7 @@ module Test
|
|
40
52
|
# Extended Message Fields
|
41
53
|
#
|
42
54
|
class ::Test::Resource < ::Protobuf::Message
|
43
|
-
optional
|
55
|
+
optional :int32, :ext_other_file_defined_field, 200, :extension => true
|
44
56
|
end
|
45
57
|
|
46
58
|
end
|
@@ -8,10 +8,25 @@ enum EnumTestType {
|
|
8
8
|
TWO = 2;
|
9
9
|
}
|
10
10
|
|
11
|
+
// Uses aliases
|
12
|
+
enum AliasedEnum {
|
13
|
+
option allow_alias = true;
|
14
|
+
|
15
|
+
THREE = 3;
|
16
|
+
TRES = 3;
|
17
|
+
|
18
|
+
FOUR = 4;
|
19
|
+
CUATRO = 4;
|
20
|
+
}
|
21
|
+
|
11
22
|
message EnumTestMessage {
|
12
23
|
optional EnumTestType non_default_enum = 1;
|
13
24
|
optional EnumTestType default_enum = 2 [default=ONE];
|
14
25
|
repeated EnumTestType repeated_enums = 3;
|
26
|
+
|
27
|
+
optional AliasedEnum alias_non_default_enum = 4;
|
28
|
+
optional AliasedEnum alias_default_enum = 5 [default=CUATRO];
|
29
|
+
repeated AliasedEnum alias_repeated_enums = 6;
|
15
30
|
}
|
16
31
|
|
17
32
|
extend test.Resource {
|