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.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +84 -5
  3. data/CONTRIBUTING.md +3 -3
  4. data/Rakefile +46 -7
  5. data/lib/protobuf/cli.rb +2 -20
  6. data/lib/protobuf/decoder.rb +74 -0
  7. data/lib/protobuf/deprecator.rb +42 -0
  8. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +17 -16
  9. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +86 -85
  10. data/lib/protobuf/encoder.rb +62 -0
  11. data/lib/protobuf/enum.rb +298 -37
  12. data/lib/protobuf/field/base_field.rb +41 -27
  13. data/lib/protobuf/field/bool_field.rb +22 -4
  14. data/lib/protobuf/field/bytes_field.rb +36 -15
  15. data/lib/protobuf/field/double_field.rb +10 -3
  16. data/lib/protobuf/field/enum_field.rb +21 -18
  17. data/lib/protobuf/field/field_array.rb +26 -16
  18. data/lib/protobuf/field/fixed32_field.rb +10 -4
  19. data/lib/protobuf/field/fixed64_field.rb +10 -3
  20. data/lib/protobuf/field/float_field.rb +18 -5
  21. data/lib/protobuf/field/int32_field.rb +14 -4
  22. data/lib/protobuf/field/int64_field.rb +14 -4
  23. data/lib/protobuf/field/integer_field.rb +9 -4
  24. data/lib/protobuf/field/message_field.rb +16 -7
  25. data/lib/protobuf/field/sfixed32_field.rb +10 -3
  26. data/lib/protobuf/field/sfixed64_field.rb +12 -7
  27. data/lib/protobuf/field/signed_integer_field.rb +7 -0
  28. data/lib/protobuf/field/sint32_field.rb +14 -4
  29. data/lib/protobuf/field/sint64_field.rb +14 -4
  30. data/lib/protobuf/field/string_field.rb +11 -1
  31. data/lib/protobuf/field/uint32_field.rb +14 -4
  32. data/lib/protobuf/field/uint64_field.rb +14 -4
  33. data/lib/protobuf/field/varint_field.rb +11 -9
  34. data/lib/protobuf/field.rb +42 -25
  35. data/lib/protobuf/generators/enum_generator.rb +12 -1
  36. data/lib/protobuf/generators/field_generator.rb +1 -1
  37. data/lib/protobuf/lifecycle.rb +3 -4
  38. data/lib/protobuf/message/fields.rb +122 -0
  39. data/lib/protobuf/message/serialization.rb +84 -0
  40. data/lib/protobuf/message.rb +21 -221
  41. data/lib/protobuf/optionable.rb +23 -0
  42. data/lib/protobuf/rpc/client.rb +2 -4
  43. data/lib/protobuf/rpc/connector.rb +0 -2
  44. data/lib/protobuf/rpc/connectors/common.rb +2 -2
  45. data/lib/protobuf/rpc/dynamic_discovery.pb.rb +14 -16
  46. data/lib/protobuf/rpc/env.rb +58 -0
  47. data/lib/protobuf/rpc/error.rb +8 -5
  48. data/lib/protobuf/rpc/middleware/exception_handler.rb +36 -0
  49. data/lib/protobuf/rpc/middleware/logger.rb +91 -0
  50. data/lib/protobuf/rpc/middleware/request_decoder.rb +83 -0
  51. data/lib/protobuf/rpc/middleware/response_encoder.rb +88 -0
  52. data/lib/protobuf/rpc/middleware/runner.rb +18 -0
  53. data/lib/protobuf/rpc/middleware.rb +25 -0
  54. data/lib/protobuf/rpc/rpc.pb.rb +15 -16
  55. data/lib/protobuf/rpc/server.rb +14 -64
  56. data/lib/protobuf/rpc/servers/socket/server.rb +0 -2
  57. data/lib/protobuf/rpc/servers/socket/worker.rb +11 -15
  58. data/lib/protobuf/rpc/servers/zmq/util.rb +4 -1
  59. data/lib/protobuf/rpc/servers/zmq/worker.rb +5 -13
  60. data/lib/protobuf/rpc/servers/zmq_runner.rb +1 -1
  61. data/lib/protobuf/rpc/service.rb +38 -72
  62. data/lib/protobuf/rpc/service_dispatcher.rb +20 -108
  63. data/lib/protobuf/version.rb +1 -2
  64. data/lib/protobuf.rb +5 -13
  65. data/protobuf.gemspec +5 -5
  66. data/spec/benchmark/tasks.rb +2 -77
  67. data/spec/functional/zmq_server_spec.rb +13 -21
  68. data/spec/lib/protobuf/cli_spec.rb +5 -43
  69. data/spec/lib/protobuf/enum_spec.rb +194 -61
  70. data/spec/lib/protobuf/field_spec.rb +194 -0
  71. data/spec/lib/protobuf/generators/enum_generator_spec.rb +24 -1
  72. data/spec/lib/protobuf/generators/field_generator_spec.rb +6 -6
  73. data/spec/lib/protobuf/message_spec.rb +52 -70
  74. data/spec/lib/protobuf/optionable_spec.rb +46 -0
  75. data/spec/lib/protobuf/rpc/client_spec.rb +1 -93
  76. data/spec/lib/protobuf/rpc/connector_spec.rb +1 -7
  77. data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +8 -0
  78. data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +62 -0
  79. data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +49 -0
  80. data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +115 -0
  81. data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +75 -0
  82. data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +0 -6
  83. data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +10 -0
  84. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +30 -105
  85. data/spec/lib/protobuf/rpc/service_filters_spec.rb +4 -4
  86. data/spec/lib/protobuf/rpc/service_spec.rb +20 -24
  87. data/spec/lib/protobuf_spec.rb +3 -3
  88. data/spec/spec_helper.rb +5 -4
  89. data/spec/support/packed_field.rb +15 -14
  90. data/spec/support/server.rb +4 -21
  91. data/spec/support/test/defaults.pb.rb +4 -4
  92. data/spec/support/test/enum.pb.rb +13 -1
  93. data/spec/support/test/enum.proto +15 -0
  94. data/spec/support/test/extended.pb.rb +1 -1
  95. data/spec/support/test/google_unittest.pb.rb +239 -241
  96. data/spec/support/test/google_unittest_import.pb.rb +2 -2
  97. data/spec/support/test/multi_field_extensions.pb.rb +2 -2
  98. data/spec/support/test/resource.pb.rb +19 -18
  99. data/spec/support/test/resource.proto +1 -0
  100. data/spec/support/test/resource_service.rb +5 -0
  101. metadata +78 -57
  102. data/bin/rprotoc +0 -8
  103. data/lib/protobuf/enum_value.rb +0 -85
  104. data/lib/protobuf/evented.rb +0 -37
  105. data/lib/protobuf/ext/eventmachine.rb +0 -14
  106. data/lib/protobuf/field/extension_fields.rb +0 -32
  107. data/lib/protobuf/message/decoder.rb +0 -72
  108. data/lib/protobuf/message/message.rb +0 -1
  109. data/lib/protobuf/rpc/connectors/em_client.rb +0 -84
  110. data/lib/protobuf/rpc/connectors/eventmachine.rb +0 -87
  111. data/lib/protobuf/rpc/servers/evented/server.rb +0 -36
  112. data/lib/protobuf/rpc/servers/evented_runner.rb +0 -31
  113. data/spec/functional/embedded_service_spec.rb +0 -7
  114. data/spec/functional/evented_server_spec.rb +0 -64
  115. data/spec/lib/protobuf/enum_value_spec.rb +0 -29
  116. data/spec/lib/protobuf/rpc/servers/evented_server_spec.rb +0 -19
@@ -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::Evented::Server) do
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::Evented::Server }.merge(options))
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(opt)
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
- @zmq_runnger = ::Protobuf::Rpc::ZmqRunner.new(opt)
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 ::Protobuf::Field::BytesField, :escaped_bytes, 1, :default => "\000\001\007\010\014\n\r\t\013\\\\'\"\376"
19
- optional ::Protobuf::Field::DoubleField, :infinity_default, 2, :default => ::Float::INFINITY
20
- optional ::Protobuf::Field::FloatField, :neg_infinity_default, 3, :default => -::Float::INFINITY
21
- optional ::Protobuf::Field::DoubleField, :nan_default, 4, :default => ::Float::NAN
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 ::Protobuf::Field::Int32Field, :ext_other_file_defined_field, 200, :extension => true
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 {
@@ -15,7 +15,7 @@ module Test
15
15
  # Extended Message Fields
16
16
  #
17
17
  class ::Test::Resource < ::Protobuf::Message
18
- optional ::Protobuf::Field::Int64Field, :deleted_at, 300, :extension => true
18
+ optional :int64, :deleted_at, 300, :extension => true
19
19
  end
20
20
 
21
21
  end