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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 450f953345bf0510126fb5bbd1fe8e1e432b1713
4
- data.tar.gz: d61858293423248cfa6fa535b7b85a265971c292
3
+ metadata.gz: 7f5adb66133630992323a9997d949111915d8829
4
+ data.tar.gz: 7e38efbe7179f878ba6851d7b959e2c4e9227399
5
5
  SHA512:
6
- metadata.gz: 94314fef1e4ec9e3d52dc02c58c1d24425c486080393da52eb722c49955688655f6f5543041fadd5df098fb96575198cd12da95cf4adf66f0c0ac48c49db2fd9
7
- data.tar.gz: 798d0d104e6ab490fadda832837bcece0b19ff9f7509dd54d50162cfe9ce76c24d47a4af78915651135ba5153cc5da2c1c44b85476b3d5a9f8a5369620e14e7e
6
+ metadata.gz: a5753795f4b427bad944603d34eacd68ba6f649104f841ffbd6f32ba09413206f0113087b588023ffaa5390ab96ddc4b669cb72a8dde924eb3b9818f9283ad79
7
+ data.tar.gz: 9144fc91254485e6af4bb9d25db6b2401a50a63920d2749ef262069802a2d0787020a65f81ac098b0f16f0fa6ac4b1a28a231d3997c8c6b3d5a5727e0e82a563
data/CHANGES.md CHANGED
@@ -1,7 +1,86 @@
1
- 2.8.13
1
+ # Unstable
2
+
3
+ 3.0.0.rc1
2
4
  ---------
3
5
 
4
- - Backport #190 to 2.8 stable series. [#192]
6
+ A lot has changed leading up to the release of 3.0. For all the relevant changes,
7
+ see the closed [pull requests and issues list in github](https://github.com/localshred/protobuf/issues?milestone=1&state=closed).
8
+ Below is a high-level list of fixes, deprecations, breaking changes, and new APIs.
9
+
10
+ ### EventMachine is dead, Long live EventMachine
11
+
12
+ The EventMachine client and server have been removed from this gem. They code was far
13
+ too error prone and flawed to feasibly support going forward. It's recommended
14
+ to switch to the socket implementation (using `PB_CLIENT_TYPE` and `PB_SERVER_TYPE` of `socket`)
15
+ for a painless switchover. The ZMQ implementation is much more performant but
16
+ does have a dependency on libzmq.
17
+
18
+ ### Server Middlewares
19
+
20
+ The server/dispatcher stack has been converted to the Middleware pattern!
21
+ Exception handling (#162, #164), Request decoding (#160, #166), Response encoding (#161, #167),
22
+ Logging and stats (#163), and Method dispatch (#159) have all been extracted into their
23
+ own Middlewares to greatly simplify testing and further development of the server
24
+ stack, furthering our preparations for removing the socket implementations (zmq, socket)
25
+ into their own gems in version 4.0. Major props to @liveh2o for [tackling this beast](https://github.com/localshred/protobuf/tree/master/lib/protobuf/rpc/middleware).
26
+
27
+ #### Bug Fixes
28
+
29
+ - Resolve DNS names (e.g. localhost) when using ZMQ server. [#46, reported by @reddshack]
30
+ - Switched to hash based value storage for messages to fix large field tag memory issues. [#118, #165]
31
+ - `Enum.fetch` used to return an enum of any type if that is the value passed in. [#168]
32
+
33
+ #### Deprecations
34
+
35
+ __!! NOTE: These deprecated methods will be removed in v3.1. !!__
36
+
37
+ - Deprecated `BaseField#type` in favor of `#type_class`.
38
+ - Deprecated `Message.get_ext_field_by_name` in favor of `.get_extension_field` or `.get_field(name_or_tag, true)`.
39
+ - Deprecated `Message.get_ext_field_by_tag,` in favor of `.get_extension_field` or `.get_field(name_or_tag, true)`.
40
+ - Deprecated `Message.get_field_by_name,` in favor of `.get_field`.
41
+ - Deprecated `Message.get_field_by_tag,` in favor of `.get_field`.
42
+ - Deprecated `Enum.enum_by_value` in favor of `.enum_for_tag`.
43
+ - Deprecated `Enum.name_by_value` in favor of `.name_for_tag`.
44
+ - Deprecated `Enum.get_name_by_tag` in favor of `.name_for_tag`.
45
+ - Deprecated `Enum.value_by_name` in favor of `.enum_for_name`.
46
+ - Deprecated `Enum.values` in favor of `.enums`. Beware that `.enums` returns an array where `.values` returns a hash.
47
+ Use `.all_tags` if you just need all the valid tag numbers. In other words, don't do this anymore: `MyEnum.values.values.map(&:to_i).uniq`.
48
+
49
+ #### Breaking Changes
50
+
51
+ - All files/classes relating to the EventMachine client and server are gone. Use `PB_CLIENT_TYPE` and `PB_SERVER_TYPE` of `socket` instead. [#116]
52
+ - Cleaned up the `Enum` class, deprecating/renaming most methods. tl;dr, just use `MyEnum.fetch`.
53
+ See #134 for more comprehensive documentation about which methods are going and away and which are being renamed. [#134]
54
+ - Pulled `EnumValue` into `Enum`. The `EnumValue` class no longer exists. Use `Enum` for type-checking instead. [#168].
55
+ - Removed previously deprecated `bin/rprotoc` executable. Use `protoc --ruby_out=...` instead. [13fbdb9]
56
+ - Removed previously deprecated `Service#rpc` method. Use `Service#env#method_name` instead. [f391294]
57
+ - Changed the `Service#initialize` to take an `Env` object instead of separate request, method, and client parameters. [6c61bf72]
58
+ - Removed attribute readers for `Service#method_name` and `Service#client_host`. Use `Service#env` to get them instead.
59
+ - Removed `lib/protobuf/message/message.rb`. Use `lib/protobuf/message.rb` instead.
60
+ - Removed field getters from Message instances (e.g. `Message#get_field_by_name`).
61
+ Use class-level getters instead (see Deprecations section).
62
+ - Moved `lib/protobuf/message/decoder.rb` to `lib/protobuf/decoder.rb`. The module is still named `Protobuf::Decoder`.
63
+ - Removed `Protobuf::Field::ExtensionFields` class.
64
+ - Removed instance-level `max` and `min` methods from all relevant Field classes (e.g. Int32Field, Uint64Field, etc).
65
+ Use class-level methods of the same names instead. [#176, 992eb051]
66
+ - `PbError#to_response` no longer receives an argument, instead returning a new `Socketrpc::Response` object. [#147, @liveh2o]
67
+ - The Server module has been stripped of almost all methods, now simply invokes the Middleware stack for each request. [#159, @liveh2o]
68
+ - Removed `Protobuf::PROTOC_VERSION` constant now that the compiler supports any protoc version.
69
+
70
+ #### New APIs
71
+
72
+ - Added support for [enum `allow_alias` option](https://developers.google.com/protocol-buffers/docs/proto#enum). [#134]
73
+ - `Enum.all_tags` returns an array of unique tags. Use it to replace `Enum.values.values.map(&:to_i)` (`Enum.values` is deprecated).
74
+ - `Enum.enums` returns an array of all defined enums for that class (including any aliased Enums).
75
+ - Reinstated support for symbol primitive field types in generated Message code. [#170]
76
+ - `Message.get_field` accepts a second boolean parameter (default false) to return an extension field if found. [#169]
77
+ - Mirror existing `Decoder#decode_from(stream)` with `Encoder#encode_to(stream)`. [#169]
78
+ - `Server` now invokes the [middleware stack](https://github.com/localshred/protobuf/tree/master/lib/protobuf/rpc/middleware) for request handling. [#159, @liveh2o]
79
+ - Added `protobuf:compile` and `protobuf:clean` rake tasks. Simply `load 'protobuf/tasks/compile.rake'` in your Rakefile (see `compile.rake` for arguments and usage). [#142, #143]
80
+ - Add `Protobuf::Deprecator` module to alias deprecated methods. [#165]
81
+
82
+
83
+ # Stable (2.x)
5
84
 
6
85
  2.8.12
7
86
  ---------
@@ -19,14 +98,14 @@
19
98
  2.8.10
20
99
  ---------
21
100
 
22
- - Allow passing a file extension to compile/clean rake tasks. [#143, @localshred]
101
+ - Allow passing a file extension to compile/clean rake tasks. [#143]
23
102
 
24
103
  2.8.9
25
104
  ---------
26
105
 
27
106
  - Deprecated Protobuf::Lifecycle module in favor of using ActiveSupport::Notifications. [#139, @devin-c]
28
- - Modify `$LOAD_PATH` inside descriptors.rb to make it easier for other libraries to write their own compiler plugins using our pre-compiled descriptors. [#141, @localshred]
29
- - Add protobuf:clean and protobuf:compile rake tasks for use in external libraries to compile source definitions to a destination. [#142, @localshred]
107
+ - Modify `$LOAD_PATH` inside descriptors.rb to make it easier for other libraries to write their own compiler plugins using our pre-compiled descriptors. [#141]
108
+ - Add protobuf:clean and protobuf:compile rake tasks for use in external libraries to compile source definitions to a destination. [#142]
30
109
 
31
110
  2.8.8
32
111
  ---------
data/CONTRIBUTING.md CHANGED
@@ -6,11 +6,11 @@ your code merged.
6
6
 
7
7
  1. Use GitHub Issues or Pull Requests over sending an email. It's much easier for me to keep track of your issue through GitHub.
8
8
  2. For __compiler issues__, please provide both a gist for the __source definition(s)__ as well as the __generated output__ (if any).
9
- 3. For __pull requests__ for __existing issues or functionality__, please use the __base branch `2-7-stable`__ for the pull request. This helps us maintain a stable gem release strategy. All commits merged to `2-7-stable` will also be merged down to `master`.
10
- 4. For __pull requests__ for __new functionality__, please use the __base branch `master`__ for the pull request. The `master` branch is used to stage all "next iteration" work.
9
+ 3. For __existing issues or functionality__, please use __`2-8-stable`__ as the base branch for the pull request. This helps us maintain a stable gem release strategy. All commits merged to `2-8-stable` will also be merged down to `master`.
10
+ 4. For __new functionality__, please use __`master`__ as the base branch for the pull request. The `master` branch is used to stage all "next iteration" work.
11
11
  5. Be patient with me as I work on your issue.
12
12
 
13
13
  Following these simple guidelines really will help me help you. And really,
14
- that's what we're here for. :)
14
+ that's what we're here for. I'm on @localshred on twitter, let's be friends. :)
15
15
 
16
16
  ## Happy Contributing!
data/Rakefile CHANGED
@@ -1,19 +1,58 @@
1
1
  $: << ::File.expand_path('../', __FILE__)
2
2
  $: << ::File.expand_path('../spec', __FILE__)
3
3
 
4
- require "rubygems"
5
- require "rubygems/package_task"
6
- require "bundler/gem_tasks"
7
- # require "benchmark/tasks"
4
+ require 'fileutils'
5
+ require 'rubygems'
6
+ require 'rubygems/package_task'
7
+ require 'bundler/gem_tasks'
8
+ require 'benchmark/tasks'
8
9
 
9
- require "rspec/core/rake_task"
10
+ require 'rspec/core/rake_task'
10
11
 
11
- desc "Default: run specs."
12
+ desc 'Default: run specs.'
12
13
  task :default => :spec
13
14
 
14
- desc "Run specs"
15
15
  RSpec::Core::RakeTask.new(:spec)
16
16
 
17
+ desc 'Run specs'
18
+ namespace :compile do
19
+
20
+ desc 'Compile spec protos in spec/supprt/ directory'
21
+ task :spec do |task, args|
22
+ proto_path = ::File.expand_path('../spec/support/', __FILE__)
23
+ cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}}
24
+
25
+ puts cmd
26
+ exec(cmd)
27
+ end
28
+
29
+ desc 'Compile rpc protos in protos/ directory'
30
+ task :rpc do |task, args|
31
+ proto_path = ::File.expand_path('../proto', __FILE__)
32
+ output_dir = ::File.expand_path('../tmp/rpc', __FILE__)
33
+ ::FileUtils.mkdir_p(output_dir)
34
+
35
+ cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}}
36
+
37
+ puts cmd
38
+ system(cmd)
39
+
40
+ files = {
41
+ 'tmp/rpc/dynamic_discovery.pb.rb' => 'lib/protobuf/rpc',
42
+ 'tmp/rpc/rpc.pb.rb' => 'lib/protobuf/rpc',
43
+ 'tmp/rpc/google/protobuf/descriptor.pb.rb' => 'lib/protobuf/descriptors/google/protobuf',
44
+ 'tmp/rpc/google/protobuf/compiler/plugin.pb.rb' => 'lib/protobuf/descriptors/google/protobuf/compiler'
45
+ }
46
+
47
+ files.each_pair do |source_file, destination_dir|
48
+ source_file = ::File.expand_path("../#{source_file}", __FILE__)
49
+ destination_dir = ::File.expand_path("../#{destination_dir}", __FILE__)
50
+ ::FileUtils::Verbose.cp(source_file, destination_dir)
51
+ end
52
+ end
53
+
54
+ end
55
+
17
56
  task :console do
18
57
  require 'pry'
19
58
  require 'protobuf'
data/lib/protobuf/cli.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'thor'
2
2
  require 'protobuf/version'
3
3
  require 'protobuf/logger'
4
- require 'protobuf/rpc/servers/evented_runner'
5
4
  require 'protobuf/rpc/servers/socket_runner'
6
5
  require 'protobuf/rpc/servers/zmq_runner'
7
6
 
@@ -26,7 +25,6 @@ module Protobuf
26
25
  option :level, :type => :numeric, :default => ::Logger::INFO, :aliases => %w(-v), :desc => 'Log level to use, 0-5 (see http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc/)'
27
26
 
28
27
  option :socket, :type => :boolean, :aliases => %w(-s), :desc => 'Socket Mode for server and client connections.'
29
- option :evented, :type => :boolean, :aliases => %w(-m), :desc => 'Evented Mode for server and client connections (uses EventMachine).'
30
28
  option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for server and client connections.'
31
29
 
32
30
  option :beacon_interval, :type => :numeric, :desc => 'Broadcast beacons every N seconds. (default: 5)'
@@ -59,7 +57,7 @@ module Protobuf
59
57
 
60
58
  desc 'version', 'Print ruby and protoc versions and exit.'
61
59
  def version
62
- say("Ruby Protobuf v#{::Protobuf::VERSION}, protoc v#{::Protobuf::PROTOC_VERSION}")
60
+ say("Ruby Protobuf v#{::Protobuf::VERSION}")
63
61
  end
64
62
 
65
63
  no_tasks do
@@ -111,16 +109,12 @@ module Protobuf
111
109
  @runner_mode = :socket
112
110
  elsif options.zmq?
113
111
  @runner_mode = :zmq
114
- elsif options.evented?
115
- @runner_mode = :evented
116
112
  else
117
113
  case server_type = ENV["PB_SERVER_TYPE"]
118
114
  when nil, /socket/i
119
115
  @runner_mode = :socket
120
116
  when /zmq/i
121
117
  @runner_mode = :zmq
122
- when /evented/i
123
- @runner_mode = :evented
124
118
  else
125
119
  say "WARNING: You have provided incorrect option 'PB_SERVER_TYPE=#{server_type}'. Defaulting to socket mode.", :yellow
126
120
  @runner_mode = :socket
@@ -150,8 +144,6 @@ module Protobuf
150
144
  def create_runner
151
145
  debug_say("Creating #{@runner_mode} runner")
152
146
  @runner = case @runner_mode
153
- when :evented
154
- create_evented_runner
155
147
  when :zmq
156
148
  create_zmq_runner
157
149
  when :socket
@@ -172,11 +164,7 @@ module Protobuf
172
164
 
173
165
  # Internal helper to determine if the modes are multi-set which is not valid.
174
166
  def multi_mode?
175
- [
176
- options.zmq?,
177
- options.evented?,
178
- options.socket?,
179
- ].count(true) > 1
167
+ options.zmq? && options.socket?
180
168
  end
181
169
 
182
170
  # Require the application file given, exiting if the file doesn't exist.
@@ -211,12 +199,6 @@ module Protobuf
211
199
  exit(1)
212
200
  end
213
201
 
214
- def create_evented_runner
215
- require 'protobuf/evented'
216
-
217
- @runner = ::Protobuf::Rpc::EventedRunner.new(runner_options)
218
- end
219
-
220
202
  def create_socket_runner
221
203
  require 'protobuf/socket'
222
204
 
@@ -0,0 +1,74 @@
1
+ require 'protobuf/wire_type'
2
+ require 'protobuf/exceptions'
3
+
4
+ module Protobuf
5
+ class Decoder
6
+
7
+ # Read bytes from +stream+ and pass to +message+ object.
8
+ def self.decode_each_field(stream, &block)
9
+ until stream.eof?
10
+ tag, bytes = read_field(stream)
11
+ block.call(tag, bytes)
12
+ end
13
+ end
14
+
15
+ def self.read_field(stream)
16
+ tag, wire_type = read_key(stream)
17
+ bytes = case wire_type
18
+ when ::Protobuf::WireType::VARINT then
19
+ read_varint(stream)
20
+ when ::Protobuf::WireType::FIXED64 then
21
+ read_fixed64(stream)
22
+ when ::Protobuf::WireType::LENGTH_DELIMITED then
23
+ read_length_delimited(stream)
24
+ when ::Protobuf::WireType::FIXED32 then
25
+ read_fixed32(stream)
26
+ when ::Protobuf::WireType::START_GROUP then
27
+ raise NotImplementedError, 'Group is deprecated.'
28
+ when ::Protobuf::WireType::END_GROUP then
29
+ raise NotImplementedError, 'Group is deprecated.'
30
+ else
31
+ raise InvalidWireType, wire_type
32
+ end
33
+
34
+ return tag, bytes
35
+ end
36
+
37
+ # Read 32-bit string value from +stream+.
38
+ def self.read_fixed32(stream)
39
+ stream.read(4)
40
+ end
41
+
42
+ # Read 64-bit string value from +stream+.
43
+ def self.read_fixed64(stream)
44
+ stream.read(8)
45
+ end
46
+
47
+ # Read key pair (tag and wire-type) from +stream+.
48
+ def self.read_key(stream)
49
+ bits = read_varint(stream)
50
+ wire_type = bits & 0x07
51
+ tag = bits >> 3
52
+ [tag, wire_type]
53
+ end
54
+
55
+ # Read length-delimited string value from +stream+.
56
+ def self.read_length_delimited(stream)
57
+ value_length = read_varint(stream)
58
+ stream.read(value_length)
59
+ end
60
+
61
+ # Read varint integer value from +stream+.
62
+ def self.read_varint(stream)
63
+ value = index = 0
64
+ begin
65
+ byte = stream.readbyte
66
+ value |= (byte & 0x7f) << (7 * index)
67
+ index += 1
68
+ end while (byte & 0x80).nonzero?
69
+ value
70
+ end
71
+
72
+ end
73
+ end
74
+
@@ -0,0 +1,42 @@
1
+ module Protobuf
2
+ module Deprecator
3
+
4
+ def warn_deprecated(old_method, new_method)
5
+ $stderr.puts %Q{[DEPRECATED] #{self.name}.#{old_method} is deprecated and will disappear in a future version.
6
+ Please use #{self.name}.#{new_method} instead.\n}
7
+ end
8
+
9
+ # Given deprecations should be a hash whose keys are the new methods
10
+ # and values are a list of deprecated methods that should send to t
11
+ def deprecate_method(old_method, new_method)
12
+ class_eval(<<-DEPRECATED, __FILE__, __LINE__ + 1)
13
+ def #{old_method}(*args)
14
+ warn_deprecated("#{old_method}", "#{new_method}")
15
+ new_meth = method("#{new_method}")
16
+ if new_meth.arity == 0
17
+ __send__("#{new_method}")
18
+ else
19
+ __send__("#{new_method}", *args)
20
+ end
21
+ end
22
+ DEPRECATED
23
+ end
24
+
25
+ # Given deprecations should be a hash whose keys are the new methods
26
+ # and values are a list of deprecated methods that should send to t
27
+ def deprecate_class_method(old_method, new_method)
28
+ class_eval(<<-DEPRECATED, __FILE__, __LINE__ + 1)
29
+ def self.#{old_method}(*args)
30
+ warn_deprecated("#{old_method}", "#{new_method}")
31
+ new_meth = method("#{new_method}")
32
+ if new_meth.arity == 0
33
+ __send__("#{new_method}")
34
+ else
35
+ __send__("#{new_method}", *args)
36
+ end
37
+ end
38
+ DEPRECATED
39
+ end
40
+
41
+ end
42
+ end
@@ -3,49 +3,50 @@
3
3
  #
4
4
  require 'protobuf/message'
5
5
 
6
+
6
7
  ##
7
8
  # Imports
8
9
  #
9
10
  require 'google/protobuf/descriptor.pb'
10
11
 
11
12
  module Google
12
-
13
13
  module Protobuf
14
-
15
14
  module Compiler
16
-
15
+
17
16
  ##
18
17
  # Message Classes
19
18
  #
20
19
  class CodeGeneratorRequest < ::Protobuf::Message; end
21
20
  class CodeGeneratorResponse < ::Protobuf::Message
22
21
  class File < ::Protobuf::Message; end
22
+
23
23
  end
24
-
24
+
25
+
26
+
25
27
  ##
26
28
  # Message Fields
27
29
  #
28
30
  class CodeGeneratorRequest
29
- repeated ::Protobuf::Field::StringField, :file_to_generate, 1
30
- optional ::Protobuf::Field::StringField, :parameter, 2
31
+ repeated :string, :file_to_generate, 1
32
+ optional :string, :parameter, 2
31
33
  repeated ::Google::Protobuf::FileDescriptorProto, :proto_file, 15
32
34
  end
33
-
35
+
34
36
  class CodeGeneratorResponse
35
37
  class File
36
- optional ::Protobuf::Field::StringField, :name, 1
37
- optional ::Protobuf::Field::StringField, :insertion_point, 2
38
- optional ::Protobuf::Field::StringField, :content, 15
38
+ optional :string, :name, 1
39
+ optional :string, :insertion_point, 2
40
+ optional :string, :content, 15
39
41
  end
40
-
41
- optional ::Protobuf::Field::StringField, :error, 1
42
+
43
+ optional :string, :error, 1
42
44
  repeated ::Google::Protobuf::Compiler::CodeGeneratorResponse::File, :file, 15
43
45
  end
44
-
45
-
46
+
46
47
  end
47
-
48
+
48
49
  end
49
-
50
+
50
51
  end
51
52