protobuf-cucumber 3.10.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.rubocop.yml +70 -0
  4. data/.rubocop_todo.yml +145 -0
  5. data/.travis.yml +40 -0
  6. data/.yardopts +5 -0
  7. data/CHANGES.md +344 -0
  8. data/CONTRIBUTING.md +16 -0
  9. data/Gemfile +3 -0
  10. data/LICENSE.txt +22 -0
  11. data/README.md +33 -0
  12. data/Rakefile +64 -0
  13. data/bin/protoc-gen-ruby +22 -0
  14. data/bin/rpc_server +5 -0
  15. data/install-protobuf.sh +28 -0
  16. data/lib/protobuf.rb +129 -0
  17. data/lib/protobuf/cli.rb +257 -0
  18. data/lib/protobuf/code_generator.rb +120 -0
  19. data/lib/protobuf/decoder.rb +28 -0
  20. data/lib/protobuf/deprecation.rb +117 -0
  21. data/lib/protobuf/descriptors.rb +3 -0
  22. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +62 -0
  23. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +301 -0
  24. data/lib/protobuf/encoder.rb +11 -0
  25. data/lib/protobuf/enum.rb +365 -0
  26. data/lib/protobuf/exceptions.rb +9 -0
  27. data/lib/protobuf/field.rb +74 -0
  28. data/lib/protobuf/field/base_field.rb +380 -0
  29. data/lib/protobuf/field/base_field_object_definitions.rb +504 -0
  30. data/lib/protobuf/field/bool_field.rb +64 -0
  31. data/lib/protobuf/field/bytes_field.rb +78 -0
  32. data/lib/protobuf/field/double_field.rb +25 -0
  33. data/lib/protobuf/field/enum_field.rb +61 -0
  34. data/lib/protobuf/field/field_array.rb +104 -0
  35. data/lib/protobuf/field/field_hash.rb +122 -0
  36. data/lib/protobuf/field/fixed32_field.rb +25 -0
  37. data/lib/protobuf/field/fixed64_field.rb +28 -0
  38. data/lib/protobuf/field/float_field.rb +43 -0
  39. data/lib/protobuf/field/int32_field.rb +21 -0
  40. data/lib/protobuf/field/int64_field.rb +34 -0
  41. data/lib/protobuf/field/integer_field.rb +23 -0
  42. data/lib/protobuf/field/message_field.rb +51 -0
  43. data/lib/protobuf/field/sfixed32_field.rb +27 -0
  44. data/lib/protobuf/field/sfixed64_field.rb +28 -0
  45. data/lib/protobuf/field/signed_integer_field.rb +29 -0
  46. data/lib/protobuf/field/sint32_field.rb +21 -0
  47. data/lib/protobuf/field/sint64_field.rb +21 -0
  48. data/lib/protobuf/field/string_field.rb +51 -0
  49. data/lib/protobuf/field/uint32_field.rb +21 -0
  50. data/lib/protobuf/field/uint64_field.rb +21 -0
  51. data/lib/protobuf/field/varint_field.rb +77 -0
  52. data/lib/protobuf/generators/base.rb +85 -0
  53. data/lib/protobuf/generators/enum_generator.rb +39 -0
  54. data/lib/protobuf/generators/extension_generator.rb +27 -0
  55. data/lib/protobuf/generators/field_generator.rb +193 -0
  56. data/lib/protobuf/generators/file_generator.rb +262 -0
  57. data/lib/protobuf/generators/group_generator.rb +122 -0
  58. data/lib/protobuf/generators/message_generator.rb +104 -0
  59. data/lib/protobuf/generators/option_generator.rb +17 -0
  60. data/lib/protobuf/generators/printable.rb +160 -0
  61. data/lib/protobuf/generators/service_generator.rb +50 -0
  62. data/lib/protobuf/lifecycle.rb +33 -0
  63. data/lib/protobuf/logging.rb +39 -0
  64. data/lib/protobuf/message.rb +260 -0
  65. data/lib/protobuf/message/fields.rb +233 -0
  66. data/lib/protobuf/message/serialization.rb +85 -0
  67. data/lib/protobuf/optionable.rb +70 -0
  68. data/lib/protobuf/rpc/buffer.rb +78 -0
  69. data/lib/protobuf/rpc/client.rb +140 -0
  70. data/lib/protobuf/rpc/connectors/base.rb +221 -0
  71. data/lib/protobuf/rpc/connectors/ping.rb +89 -0
  72. data/lib/protobuf/rpc/connectors/socket.rb +78 -0
  73. data/lib/protobuf/rpc/connectors/zmq.rb +319 -0
  74. data/lib/protobuf/rpc/dynamic_discovery.pb.rb +50 -0
  75. data/lib/protobuf/rpc/env.rb +60 -0
  76. data/lib/protobuf/rpc/error.rb +28 -0
  77. data/lib/protobuf/rpc/error/client_error.rb +31 -0
  78. data/lib/protobuf/rpc/error/server_error.rb +43 -0
  79. data/lib/protobuf/rpc/middleware.rb +25 -0
  80. data/lib/protobuf/rpc/middleware/exception_handler.rb +40 -0
  81. data/lib/protobuf/rpc/middleware/logger.rb +95 -0
  82. data/lib/protobuf/rpc/middleware/request_decoder.rb +79 -0
  83. data/lib/protobuf/rpc/middleware/response_encoder.rb +83 -0
  84. data/lib/protobuf/rpc/middleware/runner.rb +18 -0
  85. data/lib/protobuf/rpc/rpc.pb.rb +64 -0
  86. data/lib/protobuf/rpc/rpc_method.rb +16 -0
  87. data/lib/protobuf/rpc/server.rb +39 -0
  88. data/lib/protobuf/rpc/servers/socket/server.rb +121 -0
  89. data/lib/protobuf/rpc/servers/socket/worker.rb +56 -0
  90. data/lib/protobuf/rpc/servers/socket_runner.rb +46 -0
  91. data/lib/protobuf/rpc/servers/zmq/broker.rb +194 -0
  92. data/lib/protobuf/rpc/servers/zmq/server.rb +321 -0
  93. data/lib/protobuf/rpc/servers/zmq/util.rb +48 -0
  94. data/lib/protobuf/rpc/servers/zmq/worker.rb +105 -0
  95. data/lib/protobuf/rpc/servers/zmq_runner.rb +70 -0
  96. data/lib/protobuf/rpc/service.rb +172 -0
  97. data/lib/protobuf/rpc/service_directory.rb +261 -0
  98. data/lib/protobuf/rpc/service_dispatcher.rb +45 -0
  99. data/lib/protobuf/rpc/service_filters.rb +250 -0
  100. data/lib/protobuf/rpc/stat.rb +119 -0
  101. data/lib/protobuf/socket.rb +21 -0
  102. data/lib/protobuf/tasks.rb +1 -0
  103. data/lib/protobuf/tasks/compile.rake +80 -0
  104. data/lib/protobuf/varint.rb +20 -0
  105. data/lib/protobuf/varint_pure.rb +31 -0
  106. data/lib/protobuf/version.rb +3 -0
  107. data/lib/protobuf/wire_type.rb +10 -0
  108. data/lib/protobuf/zmq.rb +21 -0
  109. data/profile.html +5103 -0
  110. data/proto/dynamic_discovery.proto +44 -0
  111. data/proto/google/protobuf/compiler/plugin.proto +147 -0
  112. data/proto/google/protobuf/descriptor.proto +779 -0
  113. data/proto/rpc.proto +69 -0
  114. data/protobuf-cucumber.gemspec +57 -0
  115. data/spec/benchmark/tasks.rb +143 -0
  116. data/spec/bin/protoc-gen-ruby_spec.rb +23 -0
  117. data/spec/encoding/all_types_spec.rb +103 -0
  118. data/spec/encoding/extreme_values_spec.rb +0 -0
  119. data/spec/functional/class_inheritance_spec.rb +52 -0
  120. data/spec/functional/code_generator_spec.rb +58 -0
  121. data/spec/functional/socket_server_spec.rb +59 -0
  122. data/spec/functional/zmq_server_spec.rb +105 -0
  123. data/spec/lib/protobuf/cli_spec.rb +317 -0
  124. data/spec/lib/protobuf/code_generator_spec.rb +87 -0
  125. data/spec/lib/protobuf/enum_spec.rb +307 -0
  126. data/spec/lib/protobuf/field/bool_field_spec.rb +91 -0
  127. data/spec/lib/protobuf/field/double_field_spec.rb +9 -0
  128. data/spec/lib/protobuf/field/enum_field_spec.rb +44 -0
  129. data/spec/lib/protobuf/field/field_array_spec.rb +105 -0
  130. data/spec/lib/protobuf/field/field_hash_spec.rb +168 -0
  131. data/spec/lib/protobuf/field/fixed32_field_spec.rb +7 -0
  132. data/spec/lib/protobuf/field/fixed64_field_spec.rb +7 -0
  133. data/spec/lib/protobuf/field/float_field_spec.rb +90 -0
  134. data/spec/lib/protobuf/field/int32_field_spec.rb +120 -0
  135. data/spec/lib/protobuf/field/int64_field_spec.rb +7 -0
  136. data/spec/lib/protobuf/field/message_field_spec.rb +132 -0
  137. data/spec/lib/protobuf/field/sfixed32_field_spec.rb +9 -0
  138. data/spec/lib/protobuf/field/sfixed64_field_spec.rb +9 -0
  139. data/spec/lib/protobuf/field/sint32_field_spec.rb +9 -0
  140. data/spec/lib/protobuf/field/sint64_field_spec.rb +9 -0
  141. data/spec/lib/protobuf/field/string_field_spec.rb +79 -0
  142. data/spec/lib/protobuf/field/uint32_field_spec.rb +7 -0
  143. data/spec/lib/protobuf/field/uint64_field_spec.rb +7 -0
  144. data/spec/lib/protobuf/field_spec.rb +192 -0
  145. data/spec/lib/protobuf/generators/base_spec.rb +154 -0
  146. data/spec/lib/protobuf/generators/enum_generator_spec.rb +82 -0
  147. data/spec/lib/protobuf/generators/extension_generator_spec.rb +42 -0
  148. data/spec/lib/protobuf/generators/field_generator_spec.rb +197 -0
  149. data/spec/lib/protobuf/generators/file_generator_spec.rb +119 -0
  150. data/spec/lib/protobuf/generators/message_generator_spec.rb +0 -0
  151. data/spec/lib/protobuf/generators/service_generator_spec.rb +99 -0
  152. data/spec/lib/protobuf/lifecycle_spec.rb +94 -0
  153. data/spec/lib/protobuf/message_spec.rb +944 -0
  154. data/spec/lib/protobuf/optionable_spec.rb +265 -0
  155. data/spec/lib/protobuf/rpc/client_spec.rb +66 -0
  156. data/spec/lib/protobuf/rpc/connectors/base_spec.rb +226 -0
  157. data/spec/lib/protobuf/rpc/connectors/ping_spec.rb +69 -0
  158. data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +34 -0
  159. data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +110 -0
  160. data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +62 -0
  161. data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +49 -0
  162. data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +115 -0
  163. data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +91 -0
  164. data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +38 -0
  165. data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +43 -0
  166. data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +55 -0
  167. data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +35 -0
  168. data/spec/lib/protobuf/rpc/service_directory_spec.rb +293 -0
  169. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +35 -0
  170. data/spec/lib/protobuf/rpc/service_filters_spec.rb +517 -0
  171. data/spec/lib/protobuf/rpc/service_spec.rb +162 -0
  172. data/spec/lib/protobuf/rpc/stat_spec.rb +101 -0
  173. data/spec/lib/protobuf/varint_spec.rb +29 -0
  174. data/spec/lib/protobuf_spec.rb +105 -0
  175. data/spec/spec_helper.rb +42 -0
  176. data/spec/support/all.rb +6 -0
  177. data/spec/support/packed_field.rb +23 -0
  178. data/spec/support/protos/all_types.data.bin +0 -0
  179. data/spec/support/protos/all_types.data.txt +119 -0
  180. data/spec/support/protos/enum.pb.rb +63 -0
  181. data/spec/support/protos/enum.proto +37 -0
  182. data/spec/support/protos/extreme_values.data.bin +0 -0
  183. data/spec/support/protos/google_unittest.bin +0 -0
  184. data/spec/support/protos/google_unittest.pb.rb +798 -0
  185. data/spec/support/protos/google_unittest.proto +884 -0
  186. data/spec/support/protos/google_unittest_custom_options.bin +0 -0
  187. data/spec/support/protos/google_unittest_custom_options.pb.rb +361 -0
  188. data/spec/support/protos/google_unittest_custom_options.proto +424 -0
  189. data/spec/support/protos/google_unittest_import.pb.rb +55 -0
  190. data/spec/support/protos/google_unittest_import.proto +73 -0
  191. data/spec/support/protos/google_unittest_import_public.pb.rb +31 -0
  192. data/spec/support/protos/google_unittest_import_public.proto +41 -0
  193. data/spec/support/protos/map-test.bin +157 -0
  194. data/spec/support/protos/map-test.pb.rb +85 -0
  195. data/spec/support/protos/map-test.proto +68 -0
  196. data/spec/support/protos/multi_field_extensions.pb.rb +59 -0
  197. data/spec/support/protos/multi_field_extensions.proto +35 -0
  198. data/spec/support/protos/resource.pb.rb +172 -0
  199. data/spec/support/protos/resource.proto +137 -0
  200. data/spec/support/resource_service.rb +23 -0
  201. data/spec/support/server.rb +65 -0
  202. data/spec/support/test_app_file.rb +2 -0
  203. data/varint_prof.rb +82 -0
  204. metadata +579 -0
@@ -0,0 +1,16 @@
1
+ # Contributing
2
+
3
+ I love accepting issues and pull requests. I only ask for a few guidelines to
4
+ be followed that will make it much easier for me to solve your issue or get
5
+ your code merged.
6
+
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
+ 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 __existing issues or functionality__, please use the latest stable branch (currently __`3-5-stable`__) as the base branch for the pull request. This helps us maintain a stable gem release strategy. All commits merged to 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
+ 5. Be patient with me as I work on your issue.
12
+
13
+ Following these simple guidelines really will help me help you. And really,
14
+ that's what we're here for. I'm on @localshred on twitter, let's be friends. :)
15
+
16
+ ## Happy Contributing!
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 BJ Neilsen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
@@ -0,0 +1,33 @@
1
+ # protobuf
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/protobuf.svg)](http://badge.fury.io/rb/protobuf)
4
+ [![Build Status](https://secure.travis-ci.org/ruby-protobuf/protobuf.svg?branch=master)](https://travis-ci.org/ruby-protobuf/protobuf)
5
+ [![Gitter chat](https://badges.gitter.im/ruby-protobuf/protobuf.svg)](https://gitter.im/ruby-protobuf/protobuf)
6
+ [![protobuf API Documentation](https://www.omniref.com/ruby/gems/protobuf.png)](https://www.omniref.com/ruby/gems/protobuf)
7
+
8
+ Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby, version 2.5.0 is currently supported.
9
+
10
+ ## Install
11
+
12
+ See our [Installation Guide][] on the [wiki][].
13
+
14
+ ## Usage
15
+
16
+ The [wiki][] contains in-depth guides on the various ways to use this gem
17
+ including [compiling definitions][], [object APIs][], [services][], [clients][], and even
18
+ an [API roadmap][].
19
+
20
+ ## Changelog
21
+
22
+ See recent changes in the [release notes][] or the [changelog][].
23
+
24
+ [google-pb]: http://code.google.com/p/protobuf "Google Protocol Buffers"
25
+ [wiki]: https://github.com/ruby-protobuf/protobuf/wiki "Wiki home page"
26
+ [Installation Guide]: https://github.com/ruby-protobuf/protobuf/wiki/Installation "Installation guide"
27
+ [compiling definitions]: https://github.com/ruby-protobuf/protobuf/wiki/Compiling-Definitions "Compiling guide"
28
+ [object APIs]: https://github.com/ruby-protobuf/protobuf/wiki/Messages-&-Enums "Message & Enum object APIs guide"
29
+ [services]: https://github.com/ruby-protobuf/protobuf/wiki/Services "Services object API guide"
30
+ [clients]: https://github.com/ruby-protobuf/protobuf/wiki/Clients "Client object API guide"
31
+ [API roadmap]: https://github.com/ruby-protobuf/protobuf/wiki/API-Roadmap "API Roadmap guide"
32
+ [release notes]: https://github.com/ruby-protobuf/protobuf/releases "Release notes"
33
+ [changelog]: https://github.com/ruby-protobuf/protobuf/blob/master/CHANGES.md "CHANGES.md"
@@ -0,0 +1,64 @@
1
+ $LOAD_PATH << ::File.expand_path('../', __FILE__)
2
+ $LOAD_PATH << ::File.expand_path('../spec', __FILE__)
3
+
4
+ require 'fileutils'
5
+ require 'rubygems'
6
+ require 'rubygems/package_task'
7
+ require 'bundler/gem_tasks'
8
+ require 'benchmark/tasks'
9
+
10
+ require 'rspec/core/rake_task'
11
+ require 'rubocop/rake_task'
12
+
13
+ RSpec::Core::RakeTask.new(:spec)
14
+ RuboCop::RakeTask.new
15
+
16
+ task :default => ['compile:spec', 'compile:rpc', :spec, :rubocop]
17
+
18
+ desc 'Run specs'
19
+ namespace :compile do
20
+
21
+ desc 'Compile spec protos in spec/supprt/ directory'
22
+ task :spec do
23
+ proto_path = ::File.expand_path('../spec/support/', __FILE__)
24
+ proto_files = Dir[File.join(proto_path, '**', '*.proto')]
25
+ cmd = %(protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{proto_files.join(' ')})
26
+
27
+ puts cmd
28
+ system(cmd)
29
+ end
30
+
31
+ desc 'Compile rpc protos in protos/ directory'
32
+ task :rpc do
33
+ proto_path = ::File.expand_path('../proto', __FILE__)
34
+ proto_files = Dir[File.join(proto_path, '**', '*.proto')]
35
+ output_dir = ::File.expand_path('../tmp/rpc', __FILE__)
36
+ ::FileUtils.mkdir_p(output_dir)
37
+
38
+ cmd = %(protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{proto_files.join(' ')})
39
+
40
+ puts cmd
41
+ system(cmd)
42
+
43
+ files = {
44
+ 'tmp/rpc/dynamic_discovery.pb.rb' => 'lib/protobuf/rpc',
45
+ 'tmp/rpc/rpc.pb.rb' => 'lib/protobuf/rpc',
46
+ 'tmp/rpc/google/protobuf/descriptor.pb.rb' => 'lib/protobuf/descriptors/google/protobuf',
47
+ 'tmp/rpc/google/protobuf/compiler/plugin.pb.rb' => 'lib/protobuf/descriptors/google/protobuf/compiler',
48
+ }
49
+
50
+ files.each_pair do |source_file, destination_dir|
51
+ source_file = ::File.expand_path("../#{source_file}", __FILE__)
52
+ destination_dir = ::File.expand_path("../#{destination_dir}", __FILE__)
53
+ ::FileUtils::Verbose.cp(source_file, destination_dir)
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+ task :console do
60
+ require 'pry'
61
+ require 'protobuf'
62
+ ARGV.clear
63
+ ::Pry.start
64
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Before requiring protobuf, ensure that we will not load any
4
+ # server or client code.
5
+ #
6
+ ENV['PB_NO_NETWORKING'] = '1'
7
+
8
+ $LOAD_PATH << ::File.expand_path("../../lib", __FILE__)
9
+ require 'protobuf'
10
+ require 'protobuf/descriptors'
11
+ require 'protobuf/code_generator'
12
+
13
+ # Ensure that no encoding conversions are done on STDIN and STDOUT since
14
+ # we are passing binary data back and forth. Otherwise these streams
15
+ # will be mangled on Windows.
16
+ STDIN.binmode
17
+ STDOUT.binmode
18
+
19
+ request_bytes = STDIN.read
20
+ code_generator = ::Protobuf::CodeGenerator.new(request_bytes)
21
+ code_generator.eval_unknown_extensions!
22
+ STDOUT.print(code_generator.response_bytes)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'protobuf/cli'
4
+ ::Protobuf::CLI.start(ARGV)
5
+ exit
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env sh
2
+
3
+ set -ex
4
+
5
+ gdie() {
6
+ echo "$@" >&2
7
+ exit 1
8
+ }
9
+
10
+ test -n "$PROTOBUF_VERSION" || die "PROTOBUF_VERSION env var is undefined"
11
+
12
+ case "$PROTOBUF_VERSION" in
13
+ 2*)
14
+ basename=protobuf-$PROTOBUF_VERSION
15
+ ;;
16
+ 3*)
17
+ basename=protobuf-cpp-$PROTOBUF_VERSION
18
+ ;;
19
+ *)
20
+ die "unknown protobuf version: $PROTOBUF_VERSION"
21
+ ;;
22
+ esac
23
+
24
+ curl -sL https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/$basename.tar.gz | tar zx
25
+
26
+ cd protobuf-$PROTOBUF_VERSION
27
+
28
+ ./configure --prefix=/usr && make -j2 && make install
@@ -0,0 +1,129 @@
1
+ require 'base64'
2
+ require 'logger'
3
+ require 'pp'
4
+ require 'socket'
5
+ require 'stringio'
6
+
7
+ require 'active_support/core_ext/object/blank'
8
+ require 'active_support/core_ext/object/try'
9
+ require 'active_support/inflector'
10
+ require 'active_support/json'
11
+ require 'active_support/notifications'
12
+ # Under MRI, this optimizes proto decoding by around 15% in tests.
13
+ # When unavailable, we fall to pure Ruby.
14
+ # rubocop:disable Lint/HandleExceptions
15
+ begin
16
+ require 'varint/varint'
17
+ rescue LoadError
18
+ end
19
+ # rubocop:enable Lint/HandleExceptions
20
+ # rubocop:disable Lint/HandleExceptions
21
+ begin
22
+ require 'protobuf_java_helpers'
23
+ rescue LoadError
24
+ end
25
+ # rubocop:enable Lint/HandleExceptions
26
+
27
+ # All top-level run time code requires, ordered by necessity
28
+ require 'protobuf/wire_type'
29
+
30
+ require 'protobuf/varint_pure'
31
+ require 'protobuf/varint'
32
+
33
+ require 'protobuf/exceptions'
34
+ require 'protobuf/deprecation'
35
+ require 'protobuf/logging'
36
+
37
+ require 'protobuf/encoder'
38
+ require 'protobuf/decoder'
39
+
40
+ require 'protobuf/optionable'
41
+ require 'protobuf/field'
42
+ require 'protobuf/enum'
43
+ require 'protobuf/message'
44
+ require 'protobuf/descriptors'
45
+
46
+ module Protobuf
47
+
48
+ class << self
49
+ # Client Host
50
+ #
51
+ # Default: `hostname` of the system
52
+ #
53
+ # The name or address of the host to use during client RPC calls.
54
+ attr_writer :client_host
55
+ end
56
+
57
+ def self.after_server_bind(&block)
58
+ ::ActiveSupport::Notifications.subscribe('after_server_bind') do |*args|
59
+ block.call(*args)
60
+ end
61
+ end
62
+
63
+ def self.before_server_bind(&block)
64
+ ::ActiveSupport::Notifications.subscribe('before_server_bind') do |*args|
65
+ block.call(*args)
66
+ end
67
+ end
68
+
69
+ def self.client_host
70
+ @client_host ||= Socket.gethostname
71
+ end
72
+
73
+ def self.connector_type_class
74
+ @connector_type_class ||= ::Protobuf::Rpc::Connectors::Socket
75
+ end
76
+
77
+ def self.connector_type_class=(type_class)
78
+ @connector_type_class = type_class
79
+ end
80
+
81
+ # GC Pause during server requests
82
+ #
83
+ # Default: false
84
+ #
85
+ # Boolean value to tell the server to disable
86
+ # the Garbage Collector when handling an rpc request.
87
+ # Once the request is completed, the GC is enabled again.
88
+ # This optomization provides a huge boost in speed to rpc requests.
89
+ def self.gc_pause_server_request?
90
+ return @gc_pause_server_request unless @gc_pause_server_request.nil?
91
+ self.gc_pause_server_request = false
92
+ end
93
+
94
+ def self.gc_pause_server_request=(value)
95
+ @gc_pause_server_request = !!value
96
+ end
97
+
98
+ # Permit unknown field on Message initialization
99
+ #
100
+ # Default: true
101
+ #
102
+ # Simple boolean to define whether we want to permit unknown fields
103
+ # on Message intialization; otherwise a ::Protobuf::FieldNotDefinedError is thrown.
104
+ def self.ignore_unknown_fields?
105
+ !defined?(@ignore_unknown_fields) || @ignore_unknown_fields
106
+ end
107
+
108
+ def self.ignore_unknown_fields=(value)
109
+ @ignore_unknown_fields = !!value
110
+ end
111
+ end
112
+
113
+ unless ENV.key?('PB_NO_NETWORKING')
114
+ require 'protobuf/rpc/client'
115
+ require 'protobuf/rpc/service'
116
+
117
+ env_connector_type = ENV.fetch('PB_CLIENT_TYPE') do
118
+ :socket
119
+ end
120
+
121
+ symbolized_connector_type = env_connector_type.to_s.downcase.strip.to_sym
122
+ if [:zmq, :socket].include?(symbolized_connector_type)
123
+ require "protobuf/#{symbolized_connector_type}"
124
+ else
125
+ require "#{env_connector_type}" # rubocop:disable Style/UnneededInterpolation
126
+ classified = env_connector_type.classify
127
+ ::Protobuf.connector_type_class = classified.constantize
128
+ end
129
+ end
@@ -0,0 +1,257 @@
1
+ require 'active_support/core_ext/hash/keys'
2
+ require 'active_support/inflector'
3
+
4
+ require 'thor'
5
+ require 'protobuf/version'
6
+ require 'protobuf/logging'
7
+ require 'protobuf/rpc/servers/socket_runner'
8
+ require 'protobuf/rpc/servers/zmq_runner'
9
+
10
+ module Protobuf
11
+ class CLI < ::Thor
12
+ include ::Thor::Actions
13
+ include ::Protobuf::Logging
14
+
15
+ attr_accessor :runner, :mode, :exit_requested
16
+
17
+ no_commands do
18
+ alias_method :exit_requested?, :exit_requested
19
+ end
20
+
21
+ default_task :start
22
+
23
+ desc 'start APP_FILE', 'Run the RPC server in the given mode, preloading the given APP_FILE. This is the default task.'
24
+
25
+ option :host, :type => :string, :default => '127.0.0.1', :aliases => %w(-o), :desc => 'Host to bind.'
26
+ option :port, :type => :numeric, :default => 9399, :aliases => %w(-p), :desc => 'Master Port to bind.'
27
+
28
+ option :backlog, :type => :numeric, :default => 100, :aliases => %w(-b), :desc => 'Backlog for listening socket when using Socket Server.'
29
+ option :threshold, :type => :numeric, :default => 100, :aliases => %w(-t), :desc => 'Multi-threaded Socket Server cleanup threshold.'
30
+ option :threads, :type => :numeric, :default => 5, :aliases => %w(-r), :desc => 'Number of worker threads to run. Only applicable in --zmq mode.'
31
+
32
+ option :log, :type => :string, :default => STDOUT, :aliases => %w(-l), :desc => 'Log file or device. Default is STDOUT.'
33
+ 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/)'
34
+
35
+ option :socket, :type => :boolean, :aliases => %w(-s), :desc => 'Socket Mode for server and client connections.'
36
+ option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for server and client connections.'
37
+
38
+ option :beacon_interval, :type => :numeric, :desc => 'Broadcast beacons every N seconds. (default: 5)'
39
+ option :beacon_port, :type => :numeric, :desc => 'Broadcast beacons to this port (default: value of ServiceDirectory.port)'
40
+ option :broadcast_beacons, :type => :boolean, :desc => 'Broadcast beacons for dynamic discovery (Currently only available with ZeroMQ).'
41
+ option :broadcast_busy, :type => :boolean, :default => false, :desc => 'Remove busy nodes from cluster when all workers are busy (Currently only available with ZeroMQ).'
42
+ option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.'
43
+ option :gc_pause_request, :type => :boolean, :default => false, :desc => 'DEPRECATED: Enable/Disable GC pause during request.'
44
+ option :print_deprecation_warnings, :type => :boolean, :default => nil, :desc => 'Cause use of deprecated fields to be printed or ignored.'
45
+ option :workers_only, :type => :boolean, :default => false, :desc => "Starts process with only workers (no broker/frontend is started) only relevant for Zmq Server"
46
+ option :worker_port, :type => :numeric, :default => nil, :desc => "Port for 'backend' where workers connect (defaults to port + 1)"
47
+ option :zmq_inproc, :type => :boolean, :default => true, :desc => 'Use inproc protocol for zmq Server/Broker/Worker'
48
+
49
+ def start(app_file)
50
+ debug_say('Configuring the rpc_server process')
51
+
52
+ configure_logger
53
+ configure_traps
54
+ configure_runner_mode
55
+ create_runner
56
+ configure_process_name(app_file)
57
+ configure_gc
58
+ configure_deprecation_warnings
59
+
60
+ require_application(app_file) unless exit_requested?
61
+ start_server unless exit_requested?
62
+ rescue => e
63
+ say_and_exit('ERROR: RPC Server failed to start.', e)
64
+ end
65
+
66
+ desc 'version', 'Print ruby and protoc versions and exit.'
67
+ def version
68
+ say("Ruby Protobuf v#{::Protobuf::VERSION}")
69
+ end
70
+
71
+ no_tasks do
72
+
73
+ # Tell protobuf how to handle the printing of deprecated field usage.
74
+ def configure_deprecation_warnings
75
+ ::Protobuf.print_deprecation_warnings =
76
+ if options.print_deprecation_warnings.nil?
77
+ !ENV.key?("PB_IGNORE_DEPRECATIONS")
78
+ else
79
+ options.print_deprecation_warnings?
80
+ end
81
+ end
82
+
83
+ # If we pause during request we don't need to pause in serialization
84
+ def configure_gc
85
+ say "DEPRECATED: The gc_pause_request option is deprecated and will be removed in 4.0." if options.gc_pause_request?
86
+
87
+ debug_say('Configuring gc')
88
+
89
+ ::Protobuf.gc_pause_server_request =
90
+ if defined?(JRUBY_VERSION)
91
+ # GC.enable/disable are noop's on Jruby
92
+ false
93
+ else
94
+ options.gc_pause_request?
95
+ end
96
+ end
97
+
98
+ # Setup the protobuf logger.
99
+ def configure_logger
100
+ debug_say('Configuring logger')
101
+
102
+ log_level = options.debug? ? ::Logger::DEBUG : options.level
103
+
104
+ ::Protobuf::Logging.initialize_logger(options.log, log_level)
105
+
106
+ # Debug output the server options to the log file.
107
+ logger.debug { 'Debugging options:' }
108
+ logger.debug { options.inspect }
109
+ end
110
+
111
+ # Re-write the $0 var to have a nice process name in ps.
112
+ def configure_process_name(app_file)
113
+ debug_say('Configuring process name')
114
+ $0 = "rpc_server --#{mode} #{options.host}:#{options.port} #{app_file}"
115
+ end
116
+
117
+ # Configure the mode of the server and the runner class.
118
+ def configure_runner_mode
119
+ debug_say('Configuring runner mode')
120
+ server_type = ENV["PB_SERVER_TYPE"]
121
+
122
+ self.mode = if multi_mode?
123
+ say('WARNING: You have provided multiple mode options. Defaulting to socket mode.', :yellow)
124
+ :socket
125
+ elsif options.zmq?
126
+ :zmq
127
+ else
128
+ case server_type
129
+ when nil, /\Asocket[[:space:]]*\z/i
130
+ :socket
131
+ when /\Azmq[[:space:]]*\z/i
132
+ :zmq
133
+ else
134
+ require server_type.to_s
135
+ server_type
136
+ end
137
+ end
138
+ end
139
+
140
+ # Configure signal traps.
141
+ # TODO: add signal handling for hot-reloading the application.
142
+ def configure_traps
143
+ debug_say('Configuring traps')
144
+
145
+ exit_signals = [:INT, :TERM]
146
+ exit_signals << :QUIT unless defined?(JRUBY_VERSION)
147
+
148
+ exit_signals.each do |signal|
149
+ debug_say("Registering trap for exit signal #{signal}", :blue)
150
+
151
+ trap(signal) do
152
+ self.exit_requested = true
153
+ shutdown_server
154
+ end
155
+ end
156
+ end
157
+
158
+ # Create the runner for the configured mode
159
+ def create_runner
160
+ debug_say("Creating #{mode} runner")
161
+ self.runner = case mode
162
+ when :zmq
163
+ create_zmq_runner
164
+ when :socket
165
+ create_socket_runner
166
+ else
167
+ say("Extension runner mode: #{mode}")
168
+ create_extension_server_runner
169
+ end
170
+ end
171
+
172
+ # Say something if we're in debug mode.
173
+ def debug_say(message, color = :yellow)
174
+ say(message, color) if options.debug?
175
+ end
176
+
177
+ # Internal helper to determine if the modes are multi-set which is not valid.
178
+ def multi_mode?
179
+ options.zmq? && options.socket?
180
+ end
181
+
182
+ # Require the application file given, exiting if the file doesn't exist.
183
+ def require_application(app_file)
184
+ debug_say('Requiring app file')
185
+ require app_file
186
+ rescue LoadError => e
187
+ say_and_exit("Failed to load application file #{app_file}", e)
188
+ end
189
+
190
+ def runner_options
191
+ opt = options.to_hash.symbolize_keys
192
+
193
+ opt[:workers_only] = (!!ENV['PB_WORKERS_ONLY']) || options.workers_only
194
+
195
+ opt
196
+ end
197
+
198
+ def say_and_exit(message, exception = nil)
199
+ message = set_color(message, :red) if options.log == STDOUT
200
+
201
+ logger.error { message }
202
+
203
+ if exception
204
+ $stderr.puts "[#{exception.class.name}] #{exception.message}"
205
+ $stderr.puts exception.backtrace.join("\n")
206
+
207
+ logger.error { "[#{exception.class.name}] #{exception.message}" }
208
+ logger.debug { exception.backtrace.join("\n") }
209
+ end
210
+
211
+ exit(1)
212
+ end
213
+
214
+ def create_extension_server_runner
215
+ classified = mode.classify
216
+ extension_server_class = classified.constantize
217
+
218
+ self.runner = extension_server_class.new(runner_options)
219
+ end
220
+
221
+ def create_socket_runner
222
+ require 'protobuf/socket'
223
+
224
+ self.runner = ::Protobuf::Rpc::SocketRunner.new(runner_options)
225
+ end
226
+
227
+ def create_zmq_runner
228
+ require 'protobuf/zmq'
229
+
230
+ self.runner = ::Protobuf::Rpc::ZmqRunner.new(runner_options)
231
+ end
232
+
233
+ def shutdown_server
234
+ logger.info { 'RPC Server shutting down...' }
235
+ runner.stop
236
+ ::Protobuf::Rpc::ServiceDirectory.instance.stop
237
+ end
238
+
239
+ # Start the runner and log the relevant options.
240
+ def start_server
241
+ debug_say('Running server')
242
+
243
+ ::ActiveSupport::Notifications.instrument("before_server_bind")
244
+
245
+ runner.run do
246
+ logger.info do
247
+ "pid #{::Process.pid} -- #{mode} RPC Server listening at #{options.host}:#{options.port}"
248
+ end
249
+
250
+ ::ActiveSupport::Notifications.instrument("after_server_bind")
251
+ end
252
+
253
+ logger.info { 'Shutdown complete' }
254
+ end
255
+ end
256
+ end
257
+ end